Use @PrimaryKey
to allow advanced configuration of the ID.
A validation policy can be given that allows specifying if zero is a valid ID value. The set of primary key columns can also be specified precisely.
Annotation Elements
Table 2-53 describes this annotation's elements.
Table 2-53 @PrimaryKey Annotation Elements
Annotation Element | Description | Default |
---|---|---|
|
(Optional) Configures the cache key type to store the object in the cache. |
|
|
(Optional) Directly specify the primary key columns. This can be used instead of |
|
|
(Optional) Configures what ID validation is done:
By default |
|
Usage
By default, EclipseLink interprets zero as null
for primitive types that cannot be null (such as int
and long
), causing zero to be an invalid value for primary keys. You can modify this setting by using the @PrimaryKey
annotation to configure an IdValidation
for an entity class. Use the eclipselink.id-validation
property to configure an IdValidation
for the entire persistence unit.
Setting the validation
element also affects how EclipseLink generates IDs: new IDs are generated only for IDs that are not valid (null
or 0
, by default); setting to NONE
disables ID generation.
Examples
Example 2-91 shows how to use this annotation.
Example 2-91 Using @PrimaryKey Annotation
@PrimaryKey(validation=IdValidation.ZERO) public class Employee implements Serializable, Cloneable { ... }
Example 2-92 shows how to use the <primary-key>
element in your eclipselink-orm.xml
file.
Example 2-92 Using @<primary-key> XML
<entity name="Employee" class="foo.Employee" access="PROPERTY"> <primary-key validation="ZERO"/> ... </entity>
See Also
For more information, see: