8.6. JDO Identity Management

Each PersistenceManager is responsible for managing the JDO identities of the persistent objects in its cache. The following methods allow you to interact with the management of JDO identities.

public Class getObjectIdClass (Class pcClass);

Returns the JDO identity class used for the given persistence-capable class.

public Object newObjectIdInstance (Class pcClass, String identityString);

This method is used to re-create JDO identity objects from the string returned by their toString method. Given a persistence-capable class and a JDO identity string, the method constructs a JDO identity object. Using the getObjectById method described below, this identity object can then be employed to obtain the persistent instance whose identity was used to create the string in the first place.

public Object getObjectId (Object pc);

Returns the JDO identity object for a persistent instance managed by this PersistenceManager.

public Object getObjectById (Object oid, boolean validate);

This method returns the persistent instance corresponding to the given JDO identity object. If the instance is already cached, the cached version will be returned. Otherwise, a new instance will be constructed, and may or may not be loaded with data from the data store.

If the validate parameter of this method is set to true, then the JDO implementation will throw a JDODataStoreException if the data store record for the given JDO identity does not exist. Otherwise, the implementation may return a cached object without validating that it has not been deleted by another persistence manager. Some implementations might return a hollow instance even when no cached object exists, and an exception will not be thrown until you attempt to access one of the object's persistent fields.


Kodo JDO always throws an exception if getObjectById is called for an object that is not in the cache and does not exist in the data store.