Java Persistence API Entities in EJB 3.0

Chapter 5 - Java Persistence API Entities

    Java Persistence API Entities in EJB 3.0

  •           The Java Persistence API provides an object or relational mapping for managing relational data in Java applications.Java Persistence consists of four areas:

                   •  The Java Persistence API

                   •  The query language

                   •  The Java Persistence Criteria API

                   •  Object/relational mapping metadata


              An entity is a lightweight persistence domain object.An entity represents a table in a relational database, and each entity instance corresponds to a row in that table. The primary programming artifact of an entity is the entity class, although entities can use helper classes. The persistent state of an entity is represented through either persistent fields or persistent properties.

    Requirements for Entity Classes:

                   •  The class must be annotated with the javax.persistence.Entity annotation.

                   •  The class must have a public or protected, no-argument constructor. The class may have other constructors.

                   •  The class must not be declared final. No methods or persistent instance variables must be declared final.

                   •  If an entity instance is passed by value as a detached object, such as through a session bean’s remote business interface, the class must implement the Serializable interface.

                   •  Entities may extend both entity and non-entity classes, and non-entity classes may extend entity classes.

                   •  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 through accessor or business methods.

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy