Identity
An instance is identified uniquely in the datastore via an identity value. JDO has two durable types of identity: datastore and application. With both types, the identity value is stored in one or more columns of the class’s table. Those columns become the table’s primary key.
For example, we use datastore identity for the Movie
class defined in the com.mediamania.content
package. The JDO
implementation may represent datastore identity as an INTEGER
in the relational schema. Line
[1] of Example 5-1 illustrates the use of
the oid
column to store the datastore
identity value for the Movie
table,
which is defined as the table’s primary key on line [2].
Example 5-1. Datastore identity stored in a primary-key column
CREATE TABLE Movie ( oid INTEGER [1] title VARCHAR(24), rating CHAR(4), genres CHAR(16), PRIMARY KEY(oid) [2] )
Each implementation has its own default name for this column, but you can usually specify the name that should be used.
You may have a table with no primary key defined, but instead have a unique index defined for one or more columns. With either a primary key or a unique index, the associated columns are used for storing the identity value. If you use a unique index for a JDO identity, none of the columns in the index can have a null value.
With datastore identity, either the JDO implementation or the datastore itself provides a unique identity value for each instance. The datastore identity value is separate from the fields you define in your class. The representation ...
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.