JPOX
JPOX
 JPOX Version 1.0
Configuration | Tutorials | Worked Examples | Developer
Obtaining JPOX
JPOX Preparation
JPOX Runtime
Object Identity

When persisting objects, the objects require an "identity" so as to uniquely identify them for storage and retrieval. With JDO you have 2 options for specification of this identity.

  • The default identity type is datastore identity, where you leave the specification of this identity to JPOX.
  • The other identity type is application identity, where you take control over the specification of the identity of your objects.

You can mix the specification of identity between classes if you wish, using datastore identity for some classes, and application identity for others. These are described below.

Datastore Identity

With datastore identity you are leaving the assignment of id's to JPOX. To specify that a class is to use datastore identity, you add the following to the MetaData for the class.

<class name="MyClass" identity-type="datastore">
...
</class>
            

That is, specifying the "identity-type" as 'datastore'. You don't need to add this because 'datastore' is the default, so in the absence of any value, it will be assumed to be 'datastore'.

When implementing datastore identity all JDO implementations have to provide a public class that represents this identity. If you call pm.getObjectId(...) for a class using datastore identity you will be passed an object which, in the case of JPOX will be of type org.jpox.store.OID. If you were to call "toString()" on this object you would get something like

1[OID]4[OID]mydomain.myclass
This is made up of :-
    1 = identity number of this object
    4 = type of this id (Types.INTEGER in this case)
    class-name
            

Generating unique ids for datastore identity is a mandatory requirement by the JDO specification, but does not specify how. JPOX supports the following methods for id generation:

  • Native database primary key generation (The database generates the primary key).
  • JPOX provided methods for ids generation (Poid generators).
  • User customized Poid generators.
By default, the SequenceTablePoidGenerator method is used for id generation.

Application Identity

With application identity you are taking control of the specification of id's to JPOX. Application identity requires a primary key class, and each persistent capable class may define a different class for its primary key, and different persistent capable classes can use the same primary key class, as appropriate. To specify that a class is to use application identity, you add the following to the MetaData for the class.

<class name="MyClass" identity-type="application" objectid-class="MyIdClass">
    <field name="myPrimaryKeyField" primary-key="true">
...
</class>
            

That is, specifying the "identity-type" and "objectid-class". The "objectid-class" is the class defining the identity for this class. You define the identity of the class using a Primary Key class. Please refer to the Primary Key Guide for definition of this.

Generating unique ids for application identity is an added value feature provided by JPOX. This feature is supported for simple (non-composed) primary keys only. JPOX supports the following methods for id generation:

  • Native database primary key generation (The database generates the primary key).
  • JPOX provided methods for ids generation (Poid generators).
  • User customized Poid generators.
By default, the SequenceTablePoidGenerator method is used for id generation.

Control over the Identity

By specifying whether to use datastore identity or application identity you have specified who has control over the assignment of identities. You can take this to a finer detail and define how the identities are assigned. Please go to the Identity Generation Guide for details.