Identity Methods

JDO provides methods to map between identity instances and their associated persistent instances, and between an identity instance and a String value. You can acquire an identity instance for a persistent instance by using getObjectId( ), and you can access a persistent instance if you have an identity instance with getObjectById( ). Figure 10-2 shows these methods.

Methods to map between a persistent instance and its identity

Figure 10-2. Methods to map between a persistent instance and its identity

You can also convert an identity instance to a String by using toString( ). You can then use the returned String to reconstruct a corresponding identity instance with newObjectIdInstance( ). These capabilities are the reasons why you need to define toString( ) and a constructor that accepts a single String argument. Now let’s describe the functionality of these methods in detail. These methods work for each identity type.

Get the Identity Class

You can access the identity class of a persistent class by calling the following PersistenceManager method:

Class getObjectIdClass(Class persistentClass);

Passing the Class of a persistent class that uses datastore or nondurable identity returns the implementation-defined identity class. Passing the Class of a persistent class that uses application identity returns your application identity class. The method returns null if the parameter is null, the class referenced by persistentClass is ...

Get Java Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.