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.

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access