Application Identity

You can use application identity with a datastore that allows the values in an instance to determine its identity. The values of one or more persistent fields in the instance form a unique value that is referred to as the primary key ; the fields are referred to as the primary-key fields. The application is responsible for generating the values of the primary-key fields to ensure they collectively have a unique value for each instance in the datastore. The primary-key fields must have a unique value for a given class and its subclasses that use the same application identity class.

Primary-Key Fields

You indicate that a Java field is a component of the primary key in the metadata by setting the primary-key attribute of the field’s associated field element to "true“. Each field of the primary key must have this attribute set to "true“; it has a default value of "false“. The primary-key fields of a persistent class must be persistent. Therefore, the persistence-modifier attribute of the field metadata element cannot be set to "transactional" or "none“. The primary-key fields become a property of the persistent class that cannot be changed after the class is enhanced. If you need to change the set of fields in a primary key, you will need to enhance the class again. Read access to primary-key fields is never mediated.

The type of primary-key fields must be serializable and should be one of the primitive types, String, Date, Byte, Short, Integer, Long, Float, ...

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.