#
JPA (Java Persistence API)
The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. JPA was defined as part of the EJB 3.0 specification as a replacement for the EJB 2 CMP Entity Beans specification. JPA is now considered the standard industry approach for Object to Relational Mapping (ORM) in the Java Industry.
The Java Persistence API (JPA) is a Java application programming interface specification that describes the management of relational data in applications using Java Platform (Standard Edition and Enterprise Edition).
Any enterprise application performs database operations by storing and retrieving vast amounts of data. Despite all the available technologies for storage management, application developers normally struggle to perform database operations efficiently.
JPA itself is just a specification, not a product; it cannot perform persistence or anything else by itself. JPA is just a set of interfaces and requires an implementation. Here are some of the most known JPA implementations: Hibernate, Eclipselink, Toplink, Spring Data JPA.
Here is the architecture of the Java Persistence API:
EntityManagerFactory
is a factory class of EntityManager. It creates and manages 0..n EntityManager instances.
EntityManager
is an Interface, and it manages the persistence operations on objects. It is a "factory" for Query instance.
Each Entity Manager manage 0..N Queries (it includes updates, insert, delete statements) and has an EntityTransaction class
associated.
Entities
are the persistence objects which are stored as records in the database.
EntityTransaction
stores the information related to a transaction. For each EntityManager we have 1 EntityTransaction class.
Query
is an interface and is implemented by each JPA vendor (Oracle, Redhat, Eclipse, etc) to obtain relational
objects that meet the criteria. Queries contain not only select statements, but also updates, insert, delete statements.
In this architecture we have also the Persistence class. This class contain static methods to obtain EntityManagerFactory instance.