Java Reference
In-Depth Information
5.1.1
Configuring JDO object identity
An object's persistent identity identifies it in the database. One important deci-
sion you must make when persisting a domain model with JDO is what kind of
object identity to use for each class. JDO provides three different kinds:
Application identity —Persistent identity is managed by the application and is
stored in an object's field or fields.
Datastore identity —Persistent identity is managed by the database and is not
stored in an object's field.
Nondurable identity —Objects have a unique identity in memory but not in
the database.
Nondurable identity is intended for specialized situations such as log files whose
table does not have a primary key. Because it isn't appropriate for most databases
applications, I will not spend more time discussing it. See the JDO specification
for more information about nondurable identity.
For each class in your application, you must decide whether to use datastore
identity or application identity. You can use a different type of identity for each
class in the domain model. The only constraint is that all classes in an inheritance
hierarchy must use the same type of identity.
Let's look at how application identity and datastore identity work and their
benefits and drawbacks.
Application identity
With application identity, an object's persistent identity consists of the values of
one or more of the object's fields. These primary key field or fields are mapped to
the primary key column or columns of the class's table. An object's persistent
identity is generated by either the application or the JDO implementation, which
is usually the simplest approach.
Here is an example of how to use application identity with the PendingOrder
class:
class PendingOrder {
private int id;
public int getId() { return id; }
}
<class name="PendingOrder"
identity-type="application">
<field name="id"
 
 
 
 
Search WWH ::




Custom Search