background image

Introduction to the Java Persistence API

<< Part 5. Persistence | Persistent Fields and Properties >>
<< Part 5. Persistence | Persistent Fields and Properties >>

Introduction to the Java Persistence API

Introduction to the Java Persistence API
The Java Persistence API provides an object/relational mapping facility to Java developers for
managing relational data in Java applications. Java Persistence consists of three areas:
The Java Persistence API
The query language
Object/relational mapping metadata
Entities
An entity is a lightweight persistence domain object. Typically 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 either through persistent fields or persistent
properties. These fields or properties use object/relational mapping annotations to map the
entities and entity relationships to the relational data in the underlying data store.
Requirements for Entity Classes
An entity class must follow these requirements:
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 be passed by value as a detached object, such as through a session bean's
remote business interface, the class must implement the Serializable interface.
24
C H A P T E R
2 4
685