Jakarta Persistence
This article needs additional citations for verification. (June 2010) |
Jakarta Persistence (JPA; formerly Java Persistence API) is a
Persistence in this context covers three areas:
- The API itself, defined in thefor Jakarta EE 8 and below)
jakarta.persistence
package (javax.persistence
- The Jakarta Persistence Query Language (JPQL; formerly Java Persistence Query Language)
- Object/relational metadata
The reference implementation for JPA is EclipseLink.[1]
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[2]). The JPA 2.1 specification was released 22 April 2013 (the Java EE 7 platform requires JPA 2.1[3]). The JPA 2.2 specification was released in the summer of 2017. The JPA 3.1 specification, the latest version, was released in the spring of 2022 as part of Jakarta EE 10.[1]
Entities
A persistence
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
Related technologies
Enterprise Beans
The
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
The
Service Data Object API
The designers
Hibernate
Hibernate, founded by Gavin King, provides an
Spring Data JPA[13]
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.[14]: 47
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)
- Oracle TopLink)
- WebSphere Application Server[15]
- Hibernate
- ObjectDB
- OpenJPA
- OrientDB
- Versant Corporation JPA (object database)[16]
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.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)
Jakarta Persistence 3.1
Version 3.1 was released in 2022.[1] 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.[17]
Vendors supporting Jakarta Persistence 3.1:
- DataNucleus (from version 6.0)
- EclipseLink (from version 4.0)[18]
- Hibernate (from version 6.0)[19]
See also
References
- ^ a b c "Jakarta Persistence 3.1". jakarta.ee. Retrieved 2022-07-27.
- ^ "JavaEE 6 tutorial". Oracle.
- ^ "JavaEE 7 tutorial". Oracle.
- ^ Hibernate EntityManager: Java SE environments
Hibernate EntityManager: Obtaining an EntityManager in a Java SE environment - ^ "Jakarta Persistence". jakarta.ee. Retrieved 2021-10-05.
- ^ "JSR 220 Members".
- ^ Barreto, Charlton. "SDO and JPA". Digital Walkabout. Archived from the original on 13 August 2011. Retrieved 5 May 2011.
- ^ Edwards, Mike. "SDO and Java Persistence Architecture (JPA)". Open SOA. osoa.org. Retrieved 5 May 2011.
- ^ "hibernate.org - Java Persistence with Hibernate". JBoss. Retrieved 2008-11-17.
Hibernate implements the Java Persistence object/relational javaAPI and persistence management interfaces
- ISBN 9781617290459. Retrieved 8 December 2013.
Gavin King is the founder of the Hibernate project
- ^ "JBoss.com - Industry Leadership". JBoss. Retrieved 2008-11-17.
JSR 220, EJB 3.0 Spec Committee, Gavin King, Bill Burke, Marc Fleury
- ^ "Java Persistence API FAQ". Sun Microsystems. Archived from the original on 2008-08-22. Retrieved 2010-07-01.
The Java Persistence API draws upon the best ideas from persistence technologies such as Hibernate, TopLink, and JDO
- ^ "Spring Data - Project website". Pivotal. Retrieved 2018-02-26.
- ^ Deinum et al. 2014.
- ^ "IBM WebSphere Application Server V7 Feature Pack for OSGi Applications and Java Persistence API". Download web site. IBM. 27 April 2010. Retrieved 8 December 2013.
- ^ "Versant JPA 2-Step Download". Download web site. Actian. Retrieved 8 December 2013.
- ^ "What's New in Jakarta Persistence 3.1". Eclipse Foundation.
- ^ "EclipseLink's TCK Results". Eclipse Foundation. Retrieved 2022-07-27.
- ^ "Hibernate ORM 6.0 series". hibernate.org. Retrieved 2022-07-27.
Further reading
- Deinum, Marten; Rubio, Daniel; Long, Josh; Mak, Gary (September 1, 2014). Spring Recipes: A Problem-Solution Approach (Second ed.). ISBN 978-1-4302-2499-0.
External links
General info
- Official website
- 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