Home
Entities
In the EJB 3.0 specification, entity beans have been substituted by the concept of entities, which are sometimes called entity objects, to clarify the distinction between EJB 2.1 entity beans and JPA entities (entity objects).
A JPA entity is a Java object that must match the following rules:
It is a plain old Java object (POJO) that does not have to implement any particular interface or extend a special class.
The class must not be declared final, and no methods or persistent instance variables must be declared final.
The entity class must have a no-argument constructor that is public or protected. The entity class can have other constructors as well.
The class must either be annotated with the @Entity annotation or specified in the orm.xml JPA mapping file. We will use annotations is our examples.
The class must define an attribute that is used to identify in an unambiguous way an instance of that class (it corresponds to the primary key in the mapped relational table).
Both abstract and concrete classes can be entities, and entities can extend non-entity classes (this is a significant limitation with EJB 2.x).
Note: Entities have overcome the traditional limitation that is present in EJB 2.x entity beans: They can be transferred on the wire (for example, they can be serialized over RMI-IIOP). Of course, remember to implement the java.io.Serializable interface in the entity.
ibm.com/redbooks