Jakarta Persistence

Short description: Jakarta EE persistence API

Jakarta Persistence, also known as JPA (abbreviated from the former name Java Persistence API) 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 `jakarta.persistence` package (`javax.persistence` for Jakarta EE 8 and below)
* The Jakarta Persistence Query Language (JPQL; formerly Java Persistence Query Language)
* Object/relational metadata

## Contents

* 1 History
* 2 Entities
* 2.1 Example
* 3 Query Language
* 4 Motivation
* 5 Related technologies
* 5.1 Enterprise Beans
* 5.2 Java Data Objects API
* 5.3 Hibernate
* 5.4 Spring Data JPA
* 6 Version history
* 6.1 JPA 2.0
* 6.2 JPA 2.1
* 6.3 JPA 2.2
* 6.4 Jakarta Persistence 3.0
* 6.5 Jakarta Persistence 3.1
* 6.6 Jakarta Persistence 3.2
* 7 See also
* 8 References
* 9 Further reading
* 10 External links
* 10.1 General info
* 10.2 Tutorials

## History

The final release date of the JPA 1.0 specification was 11 May 2006 as part of Java Community Process JSR 220. The JPA 2.0 specification was released 10 December 2009 (the Java EE 6 platform requires JPA 2.0[1]). The JPA 2.1 specification was released 22 April 2013 (the Java EE 7 platform requires JPA 2.1[2]). The JPA 2.2 specification was released in the summer of 2017. The reference implementation for JPA 1 and 2 was EclipseLink.

Jakarta Persistence 3.1 was released in the spring of 2022 as part of Jakarta EE 10.[3] Jakarta Persistence 3.2 was released in spring 2024, targeting inclusion in Jakarta EE 11.[4] 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 (ORM) 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 (import statements and setters/getters are omitted for simplicity).

@Entity
public class Person {
@Id
private long id;
private String firstName;
private String lastName;
private int age;

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 (for example changing the default table name in the `@Table` annotation), or to create associations between entities.

## Query Language

The Jakarta Persistence Query Language (JPQL; formerly Java 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 (such as Hibernate) or data access objects (DAO) 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 (itself part of the Java EE 5 platform) 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.[5] 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 (Container-Managed Persistence).

### 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 (CMP) 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 (ORM). 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."[6]

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.[7][8] King represented JBoss on JSR 220,[9] 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[10] 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.[11]: 47 [12]

## 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.

Vendors supporting JPA 2.0:

* Batoo JPA
* DataNucleus (formerly JPOX)
* EclipseLink (formerly Oracle TopLink)
* IBM, for WebSphere Application Server[13]
* JBoss with Hibernate
* ObjectDB
* OpenJPA
* OrientDB
* Versant Corporation JPA (object database)[14]

### JPA 2.1

Development of JPA version 2.1 began in July 2011 as JSR 338. JPA 2.1 was approved as final on 22 May 2013.

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

Vendors supporting JPA 2.1:

* DataNucleus
* EclipseLink
* Hibernate
* OpenJPA (from version 2.2.0)

### JPA 2.2

Development of JPA 2.2, a maintenance release, began in 2017 under JSR 338. The maintenance review was approved on 19 June 2017.

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

Vendors supporting JPA 2.2:

* DataNucleus (from version 5.1)
* EclipseLink (from version 2.7)
* Hibernate (from version 5.3)
* OpenJPA (from version 3.0)

### Jakarta Persistence 3.0

The JPA was renamed as Jakarta Persistence in 2019 and version 3.0 was released in 2020. This included the renaming of packages and properties from javax.persistence to jakarta.persistence.

Vendors supporting Jakarta Persistence 3.0:

* DataNucleus (from version 6.0)
* EclipseLink (from version 3.0)
* Hibernate (from version 5.5)
* OpenJPA (from version 4.0)

### Jakarta Persistence 3.1

Version 3.1 was released in 2022.[3] It is part of Jakarta EE 10, and thus requires at least Java 11 to run. It adds better UUID handling, various new JPQL functions for math and date/time handling, and other small changes.[15]

Vendors supporting Jakarta Persistence 3.1:

* DataNucleus (from version 6.0)
* EclipseLink (from version 4.0)[16]
* Hibernate (from version 6.0)[17]
* OpenJPA (from version 4.0)

### Jakarta Persistence 3.2

Version 3.2 was released in 2024.[4] It introduced a large number of API improvements along with some improvements to the query language.[18][19]

Vendors supporting Jakarta Persistence 3.2:

* EclipseLink (from version 5.0)[19]
* Hibernate (from version 7.0)[19]

## See also

* .NET Persistence API (NPA)
* JDBC

## References

1. ↑ "JavaEE 6 tutorial". Oracle. http://docs.oracle.com/javaee/6/tutorial/doc/bnacj.html#bnadb.
2. ↑ "JavaEE 7 tutorial". Oracle. https://docs.oracle.com/javaee/7/tutorial/overview007.htm.
3. ↑ 3.0 3.1 "Jakarta Persistence 3.1". jakarta.ee. https://jakarta.ee/specifications/persistence/3.1/.
4. ↑ 4.0 4.1 "Jakarta Persistence 3.2". jakarta.ee. https://jakarta.ee/specifications/persistence/3.2/.
5. ↑ Hibernate EntityManager: Java SE environments
Hibernate EntityManager: Obtaining an EntityManager in a Java SE environment
6. ↑ "Jakarta Persistence". https://jakarta.ee/specifications/persistence/3.0/jakarta-persistence-spec-3.0.html.
7. ↑ "hibernate.org - Java Persistence with Hibernate". JBoss. http://www.hibernate.org/397.html. "Hibernate implements the Java Persistence object/relational javaAPI and persistence management interfaces"
8. ↑ Java Persistence with Hibernate. Manning Publications. 8 November 2015. ISBN 9781617290459. https://books.google.com/books?id=EWVnnAEACAAJ. Retrieved 8 December 2013. "Gavin King is the founder of the Hibernate project"
9. ↑ "JBoss.com - Industry Leadership". JBoss. http://www.jboss.com/company/leadership. "JSR 220, EJB 3.0 Spec Committee, Gavin King, Bill Burke, Marc Fleury"
10. ↑ "Java Persistence API FAQ". Sun Microsystems. http://java.sun.com/javaee/overview/faq/persistence.jsp. "The Java Persistence API draws upon the best ideas from persistence technologies such as Hibernate, TopLink, and JDO"
11. ↑ Deinum et al. 2014.
12. ↑ "Spring Data - Project website". Pivotal. https://projects.spring.io/spring-data.
13. ↑ "IBM WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API". Download web site. IBM. 27 April 2010. http://www-01.ibm.com/common/ssi/cgi-bin/ssialias?subtype=ca&infotype=an&appname=iSource&supplier=897&letternum=ENUS210-129.
14. ↑ "Versant JPA 2-Step Download". Download web site. Actian. http://community.versant.com/jpa.aspx.
15. ↑ "What's New in Jakarta Persistence 3.1". Eclipse Foundation. https://newsroom.eclipse.org/eclipse-newsletter/2022/march/what’s-new-jakarta-persistence-31.
16. ↑ "EclipseLink's TCK Results". Eclipse Foundation. https://www.eclipse.org/eclipselink/releases/tck-summary.php.
17. ↑ "Hibernate ORM 6.0 series". hibernate.org. https://hibernate.org/orm/releases/6.0/.
18. ↑ "A summary of Jakarta Persistence 3.2". Hibernate. April 2024. https://in.relation.to/2024/04/01/jakarta-persistence-3/.
19. ↑ 19.0 19.1 19.2 "Jakarta Persistence 3.2". Eclipse Foundation. https://jakarta.ee/specifications/persistence/3.2/.

## Further reading

* Deinum, Marten; Rubio, Daniel; Long, Josh; Mak, Gary (September 1, 2014). Spring Recipes: A Problem-Solution Approach (Second ed.). Apress. ISBN 978-1-4302-2499-0.

## External links

| Wikibooks has a book on the topic of: Java Persistence

|

### General info

* No URL found. Please specify a URL here or add one to Wikidata.
* Documentation for the final version of the EJB3 spec (called JSR220)
* GlassFish's Persistence page
* JCP Persistence page

### Tutorials

* Java EE 6 Persistence API Javadoc
* Java EE 6 Persistence API tutorial
* Java EE 7 Persistence API Javadoc
* Java EE 7 Persistence API tutorial
* Persistence in the Java EE 5 tutorial
* Jakarta EE Specification Guide - Persistence Explained
* Jakarta EE Starter Guide - How to Store and Retrieve Data Using Jakarta Persistence
* Jakarta EE Official Tutorial - Introduction to Jakarta Persistence

* v
* t
* e

Jakarta Persistence

* DataNucleus
* EclipseLink
* Hibernate
* ObjectDB
* OpenJPA
* TopLink

* v
* t
* e

Jakarta EE specifications

Web app|

* Servlet
* Server Pages
* Expression Language
* JSTL
* Server Faces
* WebSocket

Enterprise app|

* Dependency injection
* Bean Validation
* Enterprise Beans
* JPA
* JMS
* JTA
* Mail
* JCA
* Common Annotations

Web services|

* JAX-RS
* JAX-WS
* SOAP with Attachments
* Web Services Metadata
* JAXM
* JAXR

APM|

* Management

Other|

* JAXB
* JAX-RPC
* JAF

Related|

* JAXP
* JDBC
* JMX
* Streaming API for XML

0.00

(0 votes)

Original source: https://en.wikipedia.org/wiki/Jakarta Persistence. Read more

|

Retrieved from "https://handwiki.org/wiki/index.php?title=Jakarta_Persistence&oldid=4154214"
*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template