Friday, May 11, 2012

What is Java Entity and requirements for Entity Classes

Java entity is a lightweight persistence domain object which represents a table in a relational database and each java entity instance corresponds to a row in related relational database table. Java entity class is the primary programming artifact of java entity, although entities can use helper classes also.
The java entity persistent state is represented via persistent fields or persistent properties. These persistent fields or properties use object / relational mapping annotations to map the entities and entity relationships to the relational data in the underlying relational database.

Java entities are used in Java EE JPA API. JPA provides better options in database driven desktop java applications development and J2ee web applications development.

Requirements for Java Entity Classes

There are some requirement of java entity classes which should be must follow. These requirements are mentioned below.
  • The java entity class must be annotated with the javax.persistence.Entity annotation.
  • The java entity class must have a public or protected and no-argument constructor. The entity class may also have other constructors.
  • The java entity class must not be declared as final. No class methods or persistent instance variables must be declared as final.
  •  The java entity class must implement the Serializable interface if an entity instance is passed by value as a detached object.
  • Java Entities may extend both entity & non-entity classes and just like non entity classes may extend entity classes.
  • Java entity persistent instance variables must be declared private, protected or package private and can be accessed directly only by the entity class’s methods. Clients must access the entity’s state via accessor and business methods.


1 comment:

Please enter relevant question and information.