Every JPA entity must have a primary key.
A primary key corresponds to one or more fields or properties (“attributes”) of the entity class.
A simple (i.e., non-composite) primary key must correspond to a single persistent field or property of the entity class.
The Id annotation or id XML element must be used to denote a simple primary key.
Example:
@Id
private String myId;
When the database key is composed of several columns, you have to create a composite primary key. It is made up of one or more object types (primitive or JDK)
You can specify such a composite primary key with a separate composite primary key class.
A composite primary key must correspond to either a single persistent field or property or to a set of such fields or properties.
A primary key class must be defined to represent a composite primary key.
The EmbeddedId or IdClass annotation is used to denote a composite primary key.
A simple primary key or a field or property of a composite primary key should be one of the following types:
If the primary key is a composite primary key derived from the primary key of another entity, the primary key may contain an attribute whose type is that of the primary key of the referenced entity.
Primary key class Rules:
Annotations Rules:
is used
@Id(generate=TABLE, generator="ADDRESS_TABLE_GENERATOR")
@TableGenerator(
name="ADDRESS_TABLE_GENERATOR",
tableName="EMPLOYEE_GENERATOR_TABLE",
pkColumnValue="ADDRESS_SEQ"
)
public Integer getId() {
return id;
}