JDO Predefined ID Classes
An object ID is a combination of a persistence capable class and a primary key. It provides a unique representation of a persistent object.
The following classes serve as predefined ID classes for persistence capable classes with a simple single field primary key:
- javax.jdo.identity.ByteIdentity - JDO Class
- javax.jdo.identity.CharIdentity - JDO Class
- javax.jdo.identity.IntIdentity - JDO Class
- javax.jdo.identity.LongIdentity - JDO Class
- javax.jdo.identity.ObjectIdentity - JDO Class
- javax.jdo.identity.ShortIdentity - JDO Class
- javax.jdo.identity.StringIdentity - JDO Class
- javax.jdo.identity.SingleFieldIdentity - JDO Class
Object IDs are used in many PersistenceManager
javax.jdo.PersistenceManager - JDO InterfacePersistenceManager
is the primary interface for JDO-aware application components. methods (getObjectId
, getObjectById
, getObjectByIds
, etc.) to represent objects but should not be used as the type of a primary key field in a persistence capable class.
For example, to use a String
primary key define a primary key field of type String
:
@PersistenceCapablejavax.jdo.annotations.PersistenceCapable - JDO AnnotationAnnotation for whether the class or interface is persistence-capable. public class MyClass { @PrimaryKeyjavax.jdo.annotations.PrimaryKey - JDO AnnotationAnnotation on a member to define it as a primary key member of a class or persistent interface using application identity. String id; }
Persistent objects with a String primary key (including instances of MyClass
) can be represented uniquely by StringIdentity
, as a combination of a class and a string value.