![]() | ![]() |
![]() |
| Project | Ver 1.1 | Ver 1.2 | JDO | JPA | Guides | Tools |
| 1.2 | Persistence | JDO ORM | JPA ORM | Runtime | JDO Runtime | JPA Runtime | Extensions | Developer |
![]() ![]() With application identity you are taking control of the specification of id's to JPOX. Application identity requires a primary key class (unless using SingleFieldIdentity, where one is provided for you), 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. With application identity the field(s) of the primary key will be present as field(s) of the class itself. To specify that a class is to use application identity, you add the following to the MetaData for the class.
JDO2:
<class name="MyClass" identity-type="application" objectid-class="MyIdClass">
<field name="myPrimaryKeyField" primary-key="true"/>
...
</class>
JPA1:
<entity class="org.mydomain.MyClass">
<id-class class="org.mydomain.MyIdClass"/>
<attributes>
<id name="myPrimaryKeyField"/>
</attributes>
</entity>For JDO2 we specify the identity-type and objectid-class. The objectid-class is the class defining the identity for this class. For JPA1 we specify the id field and id-class. Alternatively, if we are using annotations
JDO2:
@PersistenceCapable(objectIdClass=MyIdClass.class)
public class MyClass
{
@Persistent(primaryKey="true")
private long myPrimaryKeyField;
}
JPA1:
@Entity
@IdClass(class=MyIdClass.class)
public class MyClass
{
@Id
private long myPrimaryKeyField;
}When you have an inheritance hierarchy, you should specify the identity type and any primary-key fields in the base class for the inheritance tree. This is then used for all persistent classes in the tree. See also :-
Using application identity requires the use of a Primary Key class. In JDO 1.0 it was necessary to always provide this class. In JDO 2.0 an in-built class is available where the identity is defined in a single field. This is referred to as SingleFieldIdentity. JPOX supports this builtin class. Where the class has multiple fields that form the primary key a Primary Key class must be provided. In JPA1 when there is a single primary key field you dont need to specify the primary key class. If there are more than 1 id field then you define the id-class. See also :-
By choosing application identity you are controlling the process of identity generation for this class. This does not mean that you have a lot of work to do for this. JDO2 and JPA1 define many ways of generating these identities and JPOX supports all of these and provides some more of its own besides. See also :-
When using application identity, the class has associated field(s) that equate to the identity. As a result you can simply access the values for these field(s). Alternatively you could use a JDO identity-independent way Object id = pm.getObjectId(obj); Object id = JDOHelper.getObjectId(obj);
JDO allows implementations to support the changing of the identity of a persisted object. This is an optional feature and JPOX doesn't currently support it. |