Jakarta Persistence

Last updated

Jakarta Persistence (JPA; formerly Java Persistence API) is a Jakarta EE application programming interface specification that describes the management of relational data in enterprise Java applications.

Contents

Persistence in this context covers three areas:

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

@EntitypublicclassPerson{@Idprivatelongid;privateStringfirstName;privateStringlastName;privateintage;}

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.

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. [4] 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." [5]

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.

Service Data Object API

The designers [6] 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 that of the Java Persistence API and is considered [7] [8] 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

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. [9] [10] King represented JBoss on JSR 220, [11] the JCP expert group charged with developing JPA. This led to ongoing controversy and speculation surrounding the relationship between JPA and Hibernate.[ citation needed ] Sun Microsystems stated [12] 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. [13] :47 [14]

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:

Vendors supporting JPA 2.0:

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:

Vendors supporting JPA 2.1:

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:

Vendors supporting JPA 2.2:

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:

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:

See also

Related Research Articles

Jakarta Enterprise Beans is one of several Java APIs for modular construction of enterprise software. EJB is a server-side software component that encapsulates business logic of an application. An EJB web container provides a runtime environment for web related software components, including computer security, Java servlet lifecycle management, transaction processing, and other web services. The EJB specification is a subset of the Java EE specification.

The Jakarta Transactions, one of the Jakarta EE APIs, enables distributed transactions to be done across multiple X/Open XA resources in a Java environment. JTA was a specification developed under the Java Community Process as JSR 907. JTA provides for:

<span class="mw-page-title-main">Jakarta EE</span> Set of specifications extending Java SE

Jakarta EE, formerly Java Platform, Enterprise Edition and Java 2 Platform, Enterprise Edition (J2EE), is a set of specifications, extending Java SE with specifications for enterprise features such as distributed computing and web services. Jakarta EE applications are run on reference runtimes, which can be microservices or application servers, which handle transactions, security, scalability, concurrency and management of the components they are deploying.

Object–relational mapping in computer science is a programming technique for converting data between a relational database and the heap of an object-oriented programming language. This creates, in effect, a virtual object database that can be used from within the programming language.

Java Data Objects (JDO) is a specification of Java object persistence. One of its features is a transparency of the persistence services to the domain model. JDO persistent objects are ordinary Java programming language classes (POJOs); there is no requirement for them to implement certain interfaces or extend from special classes. JDO 1.0 was developed under the Java Community Process as JSR 12. JDO 2.0 was developed under JSR 243 and was released on May 10, 2006. JDO 2.1 was completed in Feb 2008, developed by the Apache JDO project. JDO 2.2 was released in October 2008. JDO 3.0 was released in April 2010.

Java Management Extensions (JMX) is a Java technology that supplies tools for managing and monitoring applications, system objects, devices and service-oriented networks. Those resources are represented by objects called MBeans. In the API, classes can be dynamically loaded and instantiated. Managing and monitoring applications can be designed and developed using the Java Dynamic Management Kit.

In software, a data access object (DAO) is a pattern that provides an abstract interface to some type of database or other persistence mechanism. By mapping application calls to the persistence layer, the DAO provides data operations without exposing database details. This isolation supports the single responsibility principle. It separates the data access the application needs, in terms of domain-specific objects and data types, from how these needs can be satisfied with a specific DBMS.

Hibernate ORM is an object–relational mapping tool for the Java programming language. It provides a framework for mapping an object-oriented domain model to a relational database. Hibernate handles object–relational impedance mismatch problems by replacing direct, persistent database accesses with high-level object handling functions.

Apache Beehive is a discontinued Java Application Framework that was designed to simplify the development of Java EE-based applications. It makes use of various open-source projects at Apache, such as XMLBeans. Apache Beehive uses Java 5, including JSR-175, a facility for annotating fields, methods, and classes so that they can be treated in special ways by runtime tools. It builds on the framework developed for BEA Systems WebLogic Workshop for its 8.1 series. BEA later decided to donate the code to Apache.

<span class="mw-page-title-main">NHibernate</span> Object–relational mapping solution

NHibernate is an object–relational mapping (ORM) solution for the Microsoft .NET platform. It provides a framework for mapping an object-oriented domain model to a traditional relational database. Its purpose is to relieve the developer from a significant portion of relational data persistence-related programming tasks. NHibernate is free and open-source software that is distributed under the GNU Lesser General Public License. NHibernate is a port of Hibernate.

EasyBeans is an open-source Enterprise JavaBeans (EJB) container hosted by the OW2 Consortium. The License used by EasyBeans is the LGPL. EasyBeans is the EJB 3.0 container of the JOnAS application server.

OpenJPA is an open source implementation of the Java Persistence API specification. It is an object-relational mapping (ORM) solution for the Java language, which simplifies storing objects in databases. It is open-source software distributed under the Apache License 2.0.

JBoss Tools is a set of Eclipse plugins and features designed to help JBoss and JavaEE developers develop applications. It is an umbrella project for the JBoss developed plugins that will make it into JBoss Developer Studio.

JBoss Developer Studio (JBDS) is a development environment created and currently developed by JBoss and Exadel.

The Jakarta Persistence Query Language is a platform-independent object-oriented query language defined as part of the Jakarta Persistence specification.

DataNucleus is an open source project which provides software products around data management in Java. The DataNucleus project started in 2008.

The JBoss Enterprise Application Platform is a subscription-based/open-source Java EE-based application server runtime platform used for building, deploying, and hosting highly-transactional Java applications and services developed and maintained by Red Hat. The JBoss Enterprise Application Platform is part of Red Hat's Enterprise Middleware portfolio of software. Because it is Java-based, the JBoss application server operates across platforms; it is usable on any operating system that supports Java. JBoss Enterprise Application Platform was originally called JBoss and was developed by the eponymous company JBoss, acquired by Red Hat in 2006.

The .NET Persistence API, also referred to as NPA, is a persistence and object–relational mapping (ORM) specification for the .NET framework.

Oracle TopLink is a mapping and persistence framework for Java developers. TopLink is produced by Oracle and is a part of Oracle's OracleAS, WebLogic, and OC4J servers. It is an object-persistence and object-transformation framework. TopLink provides development tools and run-time functionalities that ease the development process and help increase functionality. Persistent object-oriented data is stored in relational databases which helps build high-performance applications. Storing data in either XML or relational databases is made possible by transforming it from object-oriented data.

References

  1. 1 2 3 "Jakarta Persistence 3.1". jakarta.ee. Retrieved 2022-07-27.
  2. "JavaEE 6 tutorial". Oracle.
  3. "JavaEE 7 tutorial". Oracle.
  4. Hibernate EntityManager: Java SE environments
    Hibernate EntityManager: Obtaining an EntityManager in a Java SE environment
  5. "Jakarta Persistence". jakarta.ee. Retrieved 2021-10-05.
  6. "JSR 220 Members".
  7. Barreto, Charlton. "SDO and JPA". Digital Walkabout. Archived from the original on 13 August 2011. Retrieved 5 May 2011.
  8. Edwards, Mike. "SDO and Java Persistence Architecture (JPA)". Open SOA. osoa.org. Retrieved 5 May 2011.
  9. "hibernate.org - Java Persistence with Hibernate". JBoss. Retrieved 2008-11-17. Hibernate implements the Java Persistence object/relational javaAPI and persistence management interfaces
  10. Java Persistence with Hibernate. Manning Publications. 8 November 2015. ISBN   9781617290459 . Retrieved 8 December 2013. Gavin King is the founder of the Hibernate project
  11. "JBoss.com - Industry Leadership". JBoss. Retrieved 2008-11-17. JSR 220, EJB 3.0 Spec Committee, Gavin King, Bill Burke, Marc Fleury
  12. "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
  13. Deinum et al. 2014.
  14. "Spring Data - Project website". Pivotal. Retrieved 2018-02-26.
  15. "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.
  16. "Versant JPA 2-Step Download". Download web site. Actian . Retrieved 8 December 2013.
  17. "What's New in Jakarta Persistence 3.1". Eclipse Foundation.
  18. "EclipseLink's TCK Results". Eclipse Foundation . Retrieved 2022-07-27.
  19. "Hibernate ORM 6.0 series". hibernate.org. Retrieved 2022-07-27.

Further reading

General info

Tutorials