Java Persistence API
The Java Persistence API (JPA), in 2019 renamed to Jakarta Persistence, is a Java application programming interface specification that describes the management of relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition/Jakarta EE.
Persistence in this context covers three areas:
- the API itself, defined in the javax.persistence package
- the Java Persistence Query Language (JPQL)
- object/relational metadata
The reference implementation for JPA is EclipseLink.
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.) The JPA 2.1 specification was released 22 April 2013 (The Java EE 7 platform requires JPA 2.1.)
A persistence entity is a lightweight Java class whose state is 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 metadata. Object/relational metadata can be specified directly in the entity class file by using annotations, or in a separate XML descriptor file distributed with the application.
The Java Persistence Query Language
The Java Persistence Query Language (JPQL) 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.
Prior to the introduction of EJB 3.0 specification, many enterprise Java developers used lightweight persistent objects, provided by either persistence frameworks (for example Hibernate) or data access objects instead of entity beans. This is because entity beans, in previous EJB specifications, called for too much complicated code and heavy resource footprint, and they could be used only in Java EE application servers because of interconnections and dependencies in the source code between beans and DAO objects or persistence framework. Thus, many of the features originally presented in third-party persistence frameworks were incorporated into the Java Persistence API, and, as of 2006, projects like Hibernate (version 3.2) and TopLink Essentials have become themselves implementations of the Java Persistence API specification.
The EJB 3.0 specification (itself part of the Java EE 5 platform) included a definition of the Java Persistence API. However, end-users do not need an EJB container or a Java EE application server in order 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 (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. (As of 2009) most products supporting each of those APIs support the Java Persistence API.
The Java Persistence API specifies persistence only for relational database management systems. That is, JPA focuses on object-relational mapping (ORM) (note that there are JPA providers who support other database models besides relational database, but this is outside the scope of what JPA was designed for). Refer to JPA 2 spec section 1 introduction for clarification of the role of JPA, which states very clearly "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, as well as literally any other conceivable datastore.
Service Data Object API
The designers of the Java Persistence API aimed to provide for relational persistence, with many of the key areas taken from object-relational mapping tools such as Hibernate and TopLink. Java Persistence API improved on and replaced EJB 2.0, evidenced by its inclusion in EJB 3.0. The Service Data Objects (SDO) API (JSR 235) has a very different objective to the Java Persistence API and is considered  complementary. The SDO API is designed for service-oriented architectures, multiple data formats rather than only relational data, and multiple programming languages. The Java Community Process manages the Java version of the SDO API; the C++ version of the SDO API is managed via OASIS.
Hibernate provides an open source object-relational mapping framework for Java. Versions 3.2 and later provide an implementation for the Java Persistence API. Gavin King founded the Hibernate project. He 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 has stated that ideas came from several frameworks, including Hibernate and Java Data Objects
Spring Data JPA
An implementation of the repository abstraction that's a key building block of Domain-Driven Design based on the Java application framework Spring. Transparently supports all available JPA implementations and supports CRUD operations as well as the convenient execution of database queries.
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
- JBoss with Hibernate
- OrientDB from Orient Technologies
- Versant Corporation JPA (not relational, object database)
Development of a new version of JPA 2.1 was started in July 2011 as JSR 338. JPA 2.1 was approved as final on 22 May 2013.
Main features included were:
- Converters - allowing custom code conversions between database and object types.
- Criteria Update/Delete - allows bulk updates and deletes through the Criteria API.
- Entity Graphs - allow partial or specified fetching or merging of objects.
- JPQL/Criteria enhancements - arithmetic sub-queries, generic database functions, join ON clause, TREAT option.
- Schema Generation
- Stored Procedures - allows queries to be defined for database stored procedures.
Vendors supporting JPA 2.1
Development of a maintenance release as JPA 2.2 was started in 2017 under JSR 338. The maintenance review was approved on 19 Jun, 2017.
Main features included were:
- Add @Repeatable to all relevant annotations
- Allow all JPA annotations to be used in meta-annotations.
- Add ability to stream a query result
- Allow AttributeConverters to be CDI injectable
- Support 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)
Future JPA specification information is available here:
In November 2015, Linda DeMichiel announced on the javaee-spec users mailing that Lukas Jungmann took over as the specification lead. Linda's announcement also stated, "[w]e plan to do an MR for JPA 2.2 in the Java EE 8 time frame".
- NetBeans Jeddict
- Eclipse JPA (Dali)
- .NET Persistence API (NPA)
- SAP NetWeaver Application Server
- ↑ Guindon, Christopher. "Jakarta Persistence" (in en). https://jakarta.ee/specifications/persistence/. Retrieved 14 September 2019.
- ↑ "JavaEE 6 tutorial". Oracle. http://docs.oracle.com/javaee/6/tutorial/doc/bnacj.html#bnadb.
- ↑ "JavaEE 7 tutorial". Oracle. https://docs.oracle.com/javaee/7/tutorial/overview007.htm.
- ↑ Hibernate EntityManager: Java SE environments
Hibernate EntityManager: Obtaining an EntityManager in a Java SE environment
- ↑ "JSR 220 Members". http://jcp.org/en/jsr/detail?id=220.
- ↑ Barreto, Charlton. "SDO and JPA". Digital Walkabout. Archived from the original on 13 August 2011. https://web.archive.org/web/20110813112451/http://charltonb.typepad.com/weblog/2007/10/sdo-and-jpa.html. Retrieved 5 May 2011.
- ↑ Edwards, Mike. "SDO and Java Persistence Architecture (JPA)". Open SOA. osoa.org. http://www.osoa.org/display/Main/SDO+and+Java+Persistence+Architecture+%28JPA%29. Retrieved 5 May 2011.
- ↑ "hibernate.org - Java Persistence with Hibernate". JBoss. http://www.hibernate.org/397.html. Retrieved 2008-11-17. "Hibernate implements the Java Persistence object/relational javaAPI and persistence management interfaces"
- ↑ Java Persistence with Hibernate. Manning Publications. ISBN 9781617290459. https://books.google.com/books?id=EWVnnAEACAAJ. Retrieved 8 December 2013. "Gavin King is the founder of the Hibernate project"
- ↑ "JBoss.com - Industry Leadership". JBoss. http://www.jboss.com/company/leadership. 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. https://web.archive.org/web/20080822023926/http://java.sun.com/javaee/overview/faq/persistence.jsp. 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. https://projects.spring.io/spring-data. Retrieved 2018-02-26.
- ↑ "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. Retrieved 8 December 2013.
- ↑ "Versant JPA 2-Step Download". Download web site. Actian. http://community.versant.com/jpa.aspx. Retrieved 8 December 2013.
- ↑ "Java EE Platform Specification: email@example.com: Archive — Project Kenai". https://java.net/projects/javaee-spec/lists/users/archive/2015-11/message/1.
- ↑ Java (2015-10-27), JavaOne LIVE - Tuesday, Mission, https://www.youtube.com/watch?v=1OKEpg5zpsU#t=4h19m26s, retrieved 2016-11-08
- ↑ Jungmann, Lukas (10 October 2015). "What’s New in the Java Persistence API (JSR 338) [CON7631"]. https://events.rainfocus.com/oow15/catalog/oracle.jsp?event=javaone&search=jungmann&search.event=javaoneEvent.
- Documentation for the final version of the EJB3 spec (called JSR220)
- GlassFish's Persistence page
- JCP Persistence page
- Java EE 6 Persistence API Javadoc
- Java EE 6 Persistence API tutorial
- Java EE 7 Persistence API Javadoc
- Java EE 7 Persistence API tutorial
- JPA Tutorial by Prasad Kharkar
- JPA Tutorial from Java Code Geeks
- JPA Tutorial using OpenJPA as implementation
- Persistence in the Java EE 5 tutorial
- Goncalves, Antonio (2019). Understanding Java Persistence API 2.2. KDP. https://www.amazon.com/Understanding-JPA-2-2-Persistence-fascicle-ebook/dp/B07RWPXPS6.