Jakarta Persistence
| Company type | Specification |
|---|---|
| Industry | Software, Enterprise Java |
| Predecessor | Java Persistence API |
| Founded | May 11, 2006 |
| Products | Jakarta Persistence API, Jakarta Persistence Query Language (JPQL), ORM metadata |
| Parent | Jakarta EE platform |
Jakarta Persistence (JPA, previously known as Java Persistence API) is a specification within the Jakarta EE platform designed to handle relational data management in enterprise-level Java applications.
The concept of persistence encompasses three key components:
- The API itself, located in the
jakarta.persistencepackage (applicable to Jakarta EE 8 and earlier versions) - The Jakarta Persistence Query Language (JPQL)
- ORM metadata
History
The initial release, JPA 1.0, was completed on 11 May 2006 through the Java Community Process under JSR 220. This was succeeded by JPA 2.0 on 10 December 2009 as part of Java EE 6. JPA 2.1 followed on 22 April 2013 aligned with Java EE 7, and JPA 2.2 was introduced in mid-2017. EclipseLink functioned as the reference implementation for both JPA 1 and 2 versions.
Jakarta Persistence version 3.1 debuted in spring 2022 alongside Jakarta EE 10, with version 3.2 released in spring 2024 targeting Jakarta EE 11. Prominent implementations include EclipseLink and Hibernate.
Entities
A persistence entity refers to a lightweight Java class whose state is generally persisted in a database table. Each instance of an entity corresponds to a single row within that table. Entities frequently establish relationships with other entities via ORM metadata, which can be defined using Java annotations or external XML configuration files.
Example
A simplified example of an entity class utilizing annotations:
<syntaxhighlight lang="java"> @Entity public class Person {
@Id private long id; private String firstName; private String lastName; private int age;
} </syntaxhighlight>
Here, the @Entity annotation designates the class as an entity, while @Id specifies the primary key field. Additional annotations may be applied to further configure metadata or specify relationships.
Query Language
The Jakarta Persistence Query Language (JPQL; formerly known as Java Persistence Query Language) allows querying against entity objects stored in relational databases. Its syntax is similar to SQL, but it operates on entities rather than directly on database tables.
Motivation
Prior to the introduction of the EJB 3.0 specification, many enterprise Java developers preferred using lightweight persistent objects provided by frameworks such as Hibernate or employing data access objects (DAO) instead of traditional entity beans. Earlier versions of entity beans involved complicated coding, consumed significant resources, and relied heavily on Java EE application servers. As a result, features from third-party persistence frameworks were incorporated into the Java Persistence API, with implementations like Hibernate and TopLink Essentials emerging.
Enterprise Beans
The EJB 3.0 specification, introduced as part of Java EE 5, included the Java Persistence API. Nevertheless, applications utilizing this API are not dependent on an EJB container or a full Java EE server environment. Future iterations of JPA will be developed independently as separate JSR specifications apart from EJB. The Java Persistence API supersedes the persistence approach used in EJB 2.0 CMP (Container-Managed Persistence).
Java Data Objects API
The Java Persistence API was developed in part to merge the Java Data Objects API with the EJB 2.0 CMP API. Currently, the majority of platforms that implement these APIs also provide support for JPA.
JPA primarily addresses persistence within relational database management systems by utilizing object-relational mapping (ORM) techniques. Although certain implementations extend functionality to additional database types, these fall outside the primary focus of JPA. According to its specification, JPA aims to deliver an ORM solution tailored for Java developers working with relational databases.
By comparison, the Java Data Objects standard offers ORM and persistence capabilities across a broader range of database systems, including flat file databases and various NoSQL databases such as document databases and graph databases.
Hibernate
Hibernate, created by Gavin King, is an open source ORM framework designed for Java. Since version 3.2, it has incorporated a Java Persistence API (JPA) implementation. King represented JBoss on the JSR 220 expert group within the Java Community Process that developed JPA. This involvement has led to ongoing discussions about how JPA and Hibernate relate. Sun Microsystems recognized that JPA drew inspiration from several frameworks, including both Hibernate and Java Data Objects.
Spring Data JPA
Spring Data JPA is a repository abstraction layer within the Spring ecosystem that supports all compliant JPA providers. It streamlines CRUD operations and simplifies query execution against databases, adhering closely to domain-driven design principles.
JPA 2.0
Work on JPA 2.0 started in July 2007 under JSR 317 and was completed by 10 December 2009. This version introduced enhancements missing from JPA 1.0 but commonly found in leading ORM solutions.
Notable additions included:
- Broadened ORM support: handling collections of embedded objects with many-to-one associations, ordered lists, and mixed access strategies
- A new criteria query API
- Standardized SQL hints and metadata to facilitate DDL generation
- Integration of validation mechanisms
- Shared caching of objects
Prominent vendors implementing JPA 2.0:
- Batoo JPA
- DataNucleus (previously known as JPOX)
- EclipseLink (formerly Oracle TopLink)
- IBM (for WebSphere Application Server)
- JBoss incorporating Hibernate
- ObjectDB
- OpenJPA
- OrientDB
- Versant Corporation JPA (object database)
JPA 2.1
The development cycle for JPA 2.1 commenced in July 2011 as part of JSR 338 and concluded on 22 May 2013.
Key enhancements included:
- Support for converters enabling custom type transformations between database and application objects
- Criteria API extensions for bulk update and delete operations
- Entity graphs allowing precise control over fetch and merge behavior
- JPQL and Criteria improvements such as arithmetic subqueries, generic functions, join ON clauses, and the TREAT operator
- Automated schema generation capabilities
- Added support for stored procedures
Vendors providing implementations for JPA 2.1:
- DataNucleus
- EclipseLink
- Hibernate
- OpenJPA (starting from version 2.2.0)
JPA 2.2
This maintenance update, initiated in 2017 under JSR 338, received approval on June 19, 2017.
Notable improvements include:
- Support for the @Repeatable annotation
- Ability to use JPA annotations within metaannotations
- Query result streaming capabilities
- AttributeConverters injectable via CDI
- Compatibility with Java 8 date and time types
Implementations supporting JPA 2.2:
- DataNucleus (starting with version 5.1)
- EclipseLink (beginning at version 2.7)
- Hibernate (from version 5.3 onwards)
- OpenJPA (introduced in version 3.0)
Jakarta Persistence 3.0
In 2019, JPA was rebranded as Jakarta Persistence, with version 3.0 launched in 2020. This release updated package and property names from javax.persistence to jakarta.persistence.
Providers supporting Jakarta Persistence 3.0:
- DataNucleus (from version 6.0)
- EclipseLink (starting at version 3.0)
- Hibernate (available since version 5.5)
- OpenJPA (from version 4.0)
Jakarta Persistence 3.1
Launched in 2022 as part of Jakarta EE 10, this version requires Java 11 or higher. It introduced enhanced UUID processing, additional JPQL mathematical and date/time functions, along with other improvements.
Support for Jakarta Persistence 3.1 is provided by:
- DataNucleus (version 6.0 and above)
- EclipseLink (from version 4.0)
- Hibernate (starting at version 6.0)
- OpenJPA (version 4.0 onwards)
Jakarta Persistence 3.2
Released in 2024, this update brought significant enhancements to the API and query language.
Current vendors supporting Jakarta Persistence 3.2:
- EclipseLink (beginning with version 5.0)
- Hibernate (from version 7.0)
See also
Further reading
General info
- Final EJB3 specification documentation (JSR220)
- GlassFish persistence information
- JCP persistence overview
Tutorials
- Java EE 6 Persistence API Javadocs
- Java EE 6 Persistence API tutorial
- Java EE 7 Persistence API Javadocs
- Java EE 7 Persistence API tutorial
- Java EE 5 persistence tutorial
- Jakarta EE Specification Guide – Overview of Persistence
- Jakarta EE Starter Guide – Managing Data with Jakarta Persistence
- Official Jakarta EE Tutorial – Introduction to Jakarta Persistence