Entity
- Implemented Interfaces:
Annotation
- be a non-
finaltop-level class or static inner class, - have a
publicorprotectedconstructor with no parameters, and - have no
finalmethods or persistent instance variables.
An enum, record, or interface may not be designated as an entity.
An entity has a primary table, mapped using the Table annotation, and may have one or more secondary tables, mapped using the SecondaryTable annotation.
An entity class holds state, represented as persistent fields and properties:
- a field or property of plain maps to a single plain in one of the tables mapped by the entity,
- a field of property of plain has nested mappings to multiple columns in one of the tables mapped by the entity,
- an plain usually maps to a separate plain,
- a plain association usually maps to a plain or columns in one of the tables mapped by the entity,
- a plain association usually maps to a unique foreign key relationship (sometimes using a shared primary key),
- a plain association usually maps to a foreign key column or columns in one of the tables mapped by the associated entity, and
- a plain association usually maps to a plain.
Every entity class must have at least one field or property annotated Id or EmbeddedId holding the primary key of the entity. An entity class may optionally have a field or property annotated Version, which holds a value used to detect optimistic lock failure.
Fields or properties of an entity class are persistent by default. The Transient annotation or the Java transient keyword must be used to explicitly declare any field or property of an entity which is not persistent.
The entity plain determines whether the persistence provider accesses the state of the entity using getter and setter methods, or via direct field access. It is almost never necessary to explicitly specify an AccessType, since the default access type for an entity is determined by the placement of mapping annotations on the entity class.
Apart from its persistent fields and properties, an entity class may declare callback methods using PrePersist, PreUpdate, PreRemove, PostPersist, PostUpdate, and/or PostRemove.
- Since:
- JPA 1.0
Entity.Public Annotation Attributes
- Since:
- JPA 1.0