Skip to main content

Identity Map Pattern

Learn Identity Map Pattern (Data Access Patterns, Enterprise Design Patterns) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

What is the Identity Map Pattern? An Identity Map ensures each object is loaded only once per session , by keeping a map of already-loaded objects keyed by their identity (usually the primary key). If the same row is requested again within the same session, the cached in-memory object is returned instead of hitting the database and creating a second, separate copy. • Prevents having two different in-memory objects representing the same database row (which could drift out of sync). • Improves performance by avoiding redundant database reads within one session.

More lessons in Data Access Patterns