- Tech know how online

Java persistence API (JPA)

The Java Persistence API (JPA) of the Java Community Process is a standard for object-relational mapping( ORM) of Java objects. ORM is a method for storing objects in databases - classes and objects are mapped to tables and rows. JPA integrates into Java EE applications with Enterprise JavaBeans 3.0 (EJB3) as well as into any Java SE applications and applications developed on the basis of the Springframework. This enables portable implementation of persistent objects with standardized interfaces.

The open source projectHibernate was already widely used before the adoption of JPA and has made a name for itself as a very good framework for Object Relational Mapping (ORM). It fully supports the JPA specification and additionally extends it with useful, not yet standardized features. Even existing database schemas that cannot or should not be changed can be made usable for modern Java applications using JPA. In addition to Hibernate, other well-known implementations include EclipseLink and Apache AopenJPA.

With the JPA it is possible to work with the same mechanisms for the persistence of classes and objects in both Java-SE and Java-EE. The JPA is part of the Java Specification Request Number 220( JSR-220) and thus the official standard for Object Relational Mapping (ORM) in Java. The Java Persistence API does not necessarily have to be used in an application server.

Technology stack of the JPA

Technology stack of the JPA

The figure shows the architecture of the technologies related to the JPA. On the logical level, Java annotations are central elements of the JPA, as they are used to control the mapping and behavior of persistent classes. Originally, the EJB container was responsible for persistence mapping. With the introduction of the above specification, this has changed to the extent that it is now realized via the JPA - specifically the persistence provider implementation of this API - as a separate service.

The central concept of the Java Persistence API

A central concept of the JPA is the EntityManager, which initially shows similarities to the sessions known from Hibernate, since this also offers methods for loading, searching, saving and deleting objects. However, unlike the sessions in Hibernate, the methods of the EntityManager are named differently and are also different in terms of their behavior.

Elements of JPA

Elements of JPA

The figure shows the central elements of the JPA for the developer. The package javax.persistence is thereby authoritative for the developer, the package javax.persistence.spi defines the interfaces for the management of the persistent classes - is not however further interesting from developer view. An important class is Persistence, which acts as a bootstrap class. It creates an EntityManagerFactory and in this process internal instances of the interfaces for the management. In addition, a new class loader is installed in the Java Virtual Machine( JVM). This new class loader calls the so-called Transformer for the entity classes and all other classes that work with entities before these classes become active in the JVM. The Transformer adds additional persistence management functionality to the loaded classes.

Englisch: Java persistence API - JPA
Updated at: 04.04.2020
#Words: 493
Links: Java, application programming interface (API), standard (STD), object (O), mapping
Translations: DE

All rights reserved DATACOM Buchverlag GmbH © 2024