Skip Headers

# Cache Type and Object Identity

Previous

Next

TopLink preserves object identity through its cache using the primary key attributes of a persistent entity. These attributes may or may not be assigned through sequencing (see "Projects and Sequencing"). In a Java application, object identity is preserved if each object in memory is represented by one, and only one, object instance. Multiple retrievals of the same object return references to the same object instance–not multiple copies of the same object.

Maintaining object identity is extremely important when the application's object model contains circular references between objects. You must ensure that the two objects are referencing each other directly, rather than copies of each other. Object identity is important when multiple parts of the application may be modifying the same object simultaneously.

Oracle recommends that you always maintain object identity. Disable object identity only if absolutely necessary, for example, for read-only objects (see "Configuring Read-Only Descriptors").

You can configure how object identity is managed on a class-by-class basis. The `Descriptor` object provides the cache and identity map options described in Table: Cache and Identity Map Options.

Cache and Identity Map Options

Option (Identity Map) | Caching | Guaranteed Identity | Memory Use | Client/Server Transaction Save
--- | --- | --- | --- | ---
Full Identity Map | Yes | Yes | High | Yes
Weak Identity Map | Yes | Yes | Low | No
Soft and Hard Cache Weak Identity Maps | Yes | Yes | Lower | Yes
No Identity Map | No | No | None | No

For more information, see "Guidelines for Configuring the Cache and Identity Maps".