by, 11-05-2011 at 07:47 PM (828 Views)
In this post, I will present some useful information about Entities. I hope these will prove useful.
You may indicate the entity class by annotating it with the Entity annotation or you may denote that class as entity in the XML descriptor. The entity class must have no-arg constructor and it should either be public and protected. The entity class can have other constructors as well.
Another important thing to note about entity class is that the entity class must be a top-level class. This means that you cannot use an enum or interface as an entity.
The entity class must not be final. Also there should be no methods or persistent instance variables in the entity class declared as final.
Sometimes you may need to pass entity instance by value as a detached object. You will then be using remote interface. In such case, the entity class must implement the Serializable interface.
Entities support inheritance, polymorphic associations, and polymorphic queries.
You may choose abstract or concrete classes as entities. Entity class may inherit from non-entity classes. Also non-entity classes may inherit from entity class.
Entity class contains instance variables which may correspond to Java-Beans properties. An entity’s instance variable should not be directly accessible from clients of entity. To access the variables, methods of the entity instance should be used.
The state of the entity is available to clients only through the entity’s accessor methods (getter/setter methods) or other business methods.