The JPA framework
The Java Persistence API (JPA) is a lightweight Java persistence framework based on
Plain Old Java Object (POJO). JPA provides an object relational mapping ( ORM )
standard in Java, using which Java objects may be mapped to relational databases.
The object relational mapping in JPA is based on metadata annotations that were
introduced in Java SE 5. JPA may be used to create, query, update, and delete
database table rows using Java objects. JPA is included with the Java EE 5 platform
and may also be used with Java SE 5. JPA supports a SQL-like query language for
dynamic and static queries. JPA also supports pluggable third-party persistence
providers, which implies that a EJB container that conforms to the Enterprise
JavaBeans 3.0 JPA specification can be used with any JPA persistence provider that
also conforms to the Enterprise JavaBeans 3.0 JPA specification. JPA is based on
entities. An entity is a Java object with the following properties:
• An entity can be made persistent.
• An entity has a persistent identity with a representation of it in a data store.
• An entity instance can be created and modiied outside a transaction, but a
transaction is required to persist the entity instance to a database.
• An entity mapping to a database is described by metadata. Metadata can be
expressed as metadata annotations or an XML mapping file.
An entity is persisted to a database using an entity manager. An entity manager
is required to create, read, and persist an entity. A non-persistent Java object may
be created without an entity manager, but an entity manager requires to obtain a
reference to the Java object to make it a persistent Java object that may be mapped
to a relational database. The set of entities managed by an entity manager is called a
persistence context and each entity in a persistence context has a unique persistent
identity. An entity manager can be configured to manage a particular type of object,
map to a particular database, or be implemented by a particular persistence provider.
The persistence provider provides the backing JPA implementation. The javax.
persistence package provides the metadata annotations that may be used to map
JPA objects (the managed Java objects) to a database using a persistence.xml
configuration file, which is discussed in a subsequent section. The javax.persistence
package provides the classes and interfaces a persistence provider uses to manage the
managed entities of the JPA. The following are the main interfaces in the JPA: