There are a few advanced identity topics, which we will consider in this section.
Choosing an Identity Type
If you are not mapping your JDO object model onto an existing relational schema and you are using an implementation that supports both datastore and application identity, you frequently have the freedom to choose the form of identity. Datastore identity is the logical choice if there is not a natural primary key to identify instances of the class. It is also useful if you prefer to have the JDO implementation generate a unique identity value. Datastore identity also requires less development work on your part. But for some entities being modeled, a primary key is the most suitable solution because of a natural primary-key value that is used to identify the data.
The primary difference between datastore and application
identity in your persistent class is the need to define
equals( ) and
methods for your persistent classes that use
application identity. The only other difference is the specification
of the identity type in your metadata. You can develop a persistent
class and define an application identity class for it, but then in the
metadata you could switch between datastore and application identity.
If you do change the identity in the metadata, you need to enhance
your classes again, as the enhanced class contains identity-specific
Using Identity Versus a Query
If you want to have the flexibility of changing the type of identity used ...