Jakarta Persistence
Jakarta Persistence, also known as JPA is a Jakarta EE application programming interface specification that describes the management of relational data in enterprise Java applications.
Persistence in this context covers three areas:
- The API itself, defined in the
package - The Jakarta Persistence Query Language
- Object/relational metadata
History
Jakarta Persistence 3.1 was released in the spring of 2022 as part of Jakarta EE 10. Jakarta Persistence 3.2 was released in spring 2024, targeting inclusion in Jakarta EE 11. EclipseLink and Hibernate are compatible implementations.
Entities
A persistence entity is a lightweight Java class with its state typically persisted to a table in a relational database. Instances of such an entity correspond to individual rows in the table. Entities typically have relationships with other entities, and these relationships are expressed through object/relational mapping metadata. This metadata may be specified directly in the entity class file by using annotations or in a separate XML descriptor file distributed with the application.Example
An example entity class with ORM metadata declared using annotations.@Entity
public class Person
The
@Entity annotation declares that the class represents an entity. @Id declares the attribute which acts as the primary key of the entity. Additional annotations may be used to declare additional metadata, or to create associations between entities.Query Language
The Jakarta Persistence Query Language makes queries against entities stored in a relational database. Queries resemble SQL queries in syntax but operate against entity objects rather than directly with database tables.Motivation
Prior to the introduction of EJB 3.0 specification, many enterprise Java developers used lightweight persistent objects provided by either persistence frameworks or data access objects instead of by using entity beans. This is because entity beans, in previous EJB specifications, called for much complicated code and imposed a heavy resource footprint, and they could be used only on Java EE application servers because of interconnections and dependencies in the source code between beans and DAO objects or persistence frameworks. Thus, many of the features originally presented in third-party persistence frameworks were incorporated into the Java Persistence API, and projects such as Hibernate and TopLink Essentials have become implementations of the Java Persistence API specification.Related technologies
Enterprise Beans
The EJB 3.0 specification included a definition of the Java Persistence API. However, developers do not need an EJB container or a Java EE application server to run applications that use this persistence API. Future versions of the Java Persistence API will be defined in a separate JSR and specification rather than in the EJB JSR/specification.The Java Persistence API replaces the persistence solution of EJB 2.0 CMP.
Java Data Objects API
The Java Persistence API was developed in part to unify the Java Data Objects API and the EJB 2.0 Container Managed Persistence API. Most products supporting each of the two APIs support the Java Persistence API.The Java Persistence API specifies persistence only for relational database management systems by focusing on object-relational mapping. Some JPA providers support other database models, though this is outside the scope of JPA's design. The introduction section of the JPA specification states: "The technical objective of this work is to provide an object/relational mapping facility for the Java application developer using a Java domain model to manage a relational database."
The Java Data Objects specification supports ORM as well as persistence to other types of database models, for example, flat file databases and NoSQL databases, including document databases, graph databases any many other datastores.
Hibernate
Hibernate, founded by Gavin King, provides an open source object-relational mapping framework for Java. Versions 3.2 and later provide an implementation for the Java Persistence API. King represented JBoss on JSR 220, the JCP expert group charged with developing JPA. This led to ongoing controversy and speculation surrounding the relationship between JPA and Hibernate. Sun Microsystems stated that ideas came from several frameworks, including Hibernate and Java Data Objects.Spring Data JPA
The Spring Data JPA is an implementation of the repository abstraction that is a key building block of domain-driven design based on the Java application framework Spring. It transparently supports all available JPA implementations and supports CRUD operations as well as the convenient execution of database queries.Version history
JPA 2.0
Development of a new version of JPA 2.0 was started in July 2007 in the Java Community Process as JSR 317. JPA 2.0 was approved as final on 10 December 2009. The focus of JPA 2.0 was to address features that were present in some of the popular ORM vendors but could not gain consensus approval for JPA 1.0.Main features included were:
- Expanded object-relational mapping functionality
- * Support for collections of embedded objects, linked in the ORM with a many-to-one relationship
- * Ordered lists
- * Combinations of access types
- A criteria query API
- Standardization of SQL Hints
- Standardization of additional metadata to support DDL generation
- Support for validation
- Shared object cache support.
- Batoo JPA
- DataNucleus
- EclipseLink
- IBM, for WebSphere Application Server
- JBoss with Hibernate
- ObjectDB
- OpenJPA
- OrientDB
- Versant Corporation JPA
JPA 2.1
Main features included were:
- Converters, which allow custom code conversions between database and object types
- Criteria update/delete to allow bulk updates and deletes through the Criteria API
- Entity graphs for partial or specified fetching or merging of objects.
- JPQL/Criteria enhancements such as arithmetic subqueries, generic database functions, join ON clause and the TREAT option.
- Schema generation
- Support for stored procedures
- DataNucleus
- EclipseLink
- Hibernate
- OpenJPA
JPA 2.2
Main features included were:
- The addition of @Repeatable to all relevant annotations
- Support for JPA annotations to be used in metaannotations
- Streaming for query results
- The ability for AttributeConverters to be CDI-injectable
- Support for Java 8 date and time types
- DataNucleus
- EclipseLink
- Hibernate
- OpenJPA
Jakarta Persistence 3.0
Vendors supporting Jakarta Persistence 3.0:
- DataNucleus
- EclipseLink
- Hibernate
- OpenJPA
Jakarta Persistence 3.1
Vendors supporting Jakarta Persistence 3.1:
- DataNucleus
- EclipseLink
- Hibernate
- OpenJPA
Jakarta Persistence 3.2
Vendors supporting Jakarta Persistence 3.2:
- EclipseLink
- Hibernate
General info
-
Tutorials
Category:Java enterprise platform
Category:Java specification requests
Category:Object–relational mapping
Category:Persistence