@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface Entity
The entity class represents a database relation (table or SQL result set). An instance of the class represents a row.
The entity class can be defined as either mutable or immutable.
The mutable entity:
@Entity
public class Employee {
@Id
@Column(name = "ID")
Integer id;
@Column(name = "EMPLOYEE_NAME")
String employeeName;
@Version
@Column(name = "VERSION")
int version;
...
}
The immutable entity:
@Entity(immutable = true)
public class Employee {
@Id
@Column(name = "ID")
final Integer id;
@Column(name = "EMPLOYEE_NAME")
final String employeeName;
@Version
@Column(name = "VERSION")
final int version;
public Employee(Integer id, String employeeName, int version) {
this.id = id;
this.employeeName = employeeName;
this.version = version;
}
...
}
The entity instance is not required to be thread safe.
| Modifier and Type | Optional Element and Description |
|---|---|
boolean |
immutable
Whether the entity class is immutable.
|
java.lang.Class<? extends EntityListener> |
listener
The entity listener class.
|
Metamodel |
metamodel
The metamodel information for the Criteria API.
|
NamingType |
naming
The naming convention that maps the entity class to the database table.
|
public abstract java.lang.Class<? extends EntityListener> listener
If not specified and the entity class inherits another entity class, this value is inherited from the parent entity class.
An instance of the entity lister class is instantiated only once per entity class.
public abstract NamingType naming
If not specified and the entity class inherits another entity class, this value is inherited from the parent entity class.
public abstract boolean immutable
If not specified and the entity class inherits another entity class, this value is inherited from the parent entity class. The values must be consistent in the hierarchy.
If not specified and the entity class is a record, the class is recognized as immutable even
though this value is false.
public abstract Metamodel metamodel
If specified, the metamodel class is generated by the annotation processor.