Annotation Interface Id
- the entity class that is the root of the entity hierarchy, or
- a mapped superclass that is a (direct or indirect) superclass of all entity classes in the entity hierarchy.
The field or property to which the Id annotation is
applied should have one of the following types:
- a Java primitive type, or wrapper of a primitive type,
String,UUID,LocalDate,Date,Date,BigDecimal, orBigInteger.
The mapped column for the primary key of the entity is assumed
to be the primary key of the primary table. If no Column
annotation is specified, the primary key column name is assumed to
be the name of the primary key property or field.
For example, this field holds a generated primary key assigned by the persistence provider:
@Id @GeneratedValue
UUID uuid;
This property holds a primary key assigned by the application:
@Id
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
An entity must declare or inherit exactly one field or property
annotated @Id or @EmbeddedId unless the
entity specifies an @IdClass, in which case the
entity must have a field or property annotated @Id for
each field or property of its id class.
The @Id annotation should never be applied to a field
or property of an embeddable id or id class.
The persistence provider is permitted to use the value of the identifier and version fields or properties of an entity instance to determine whether the instance is new or detached.
- Since:
- 1.0
- See Also: