O'Reilly logo

Java Data Objects by Craig Russell, David Jordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required