![]() | |
|
Requirements on the Entity Class
The entity class MUST be annotated with the Entity annotation or denoted in the XML descriptor as an entity.
@Entity public class Operation { ... }
The entity class MUST have a no-arg constructor. The entity class may have other constructors as well. The no-arg constructor MUST be public OR protected.
The entity class MUST be a top-level class. An enum or interface SHOULD NOT be designated as an entity. The entity class MUST NOT be final. No methods or persistent instance variables of the entity class may be final.
If an entity instance is to be passed by value as a DETACHED object (e.g., through a remote interface), the entity class MUST implement the Serializable interface.
@Entity public class Operation implements Serializable { ... }
Entities support inheritance, polymorphic associations, and polymorphic queries.
Both abstract and concrete classes can be entities. Entities may extend non-entity classes as well as entity classes, and non-entity classes may extend entity classes.
The persistent state of an entity is represented by instance variables, which may correspond to JavaBeans properties. An instance variable may be directly accessed only from within the methods of the entity by the entity instance itself. Instance variables must not be accessed by clients of the entity. The state of the entity is available to clients only through the entity's ACCESSOR METHODS (getter/setter methods) or other business methods. Instance variables MUST be private, protected, or package visibility.
@Entity public class Operation implements Serializable { private int id; private Timestamp timestamp; private double operandA; private double operandB; private String operation; private double result; ... }
![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |