Java Persistence API

The Java Persistence API (JPA ) is an interface for Java applications that simplifies the assignment and transfer of objects to database entries. It simplifies the solution of the problem of object-relational mapping, which is to save run-time objects of a Java application on a single session addition (persistence ), with relational databases can be used that are not originally designed for object-oriented data structures.

The Java Persistence API was developed as a project of the JSR 220 Expert Group and first released in May 2006. The specification of the current version 2.1 was released on April 22, 2013.

EclipseLink is the reference implementation for the Java Persistence API (JPA ) 2.1 and 2.0. TopLink Essentials was the reference implementation for JPA 1.0.

Conception

In addition to the API, which is defined javax.persistence in the package, the Java Persistence consists of the following components:

Persistence Entity

A Persistence Entity is a Plain Old Java Object ( POJO ), which is usually mapped to a single table in the relational database. Instances of this class in this case correspond to the rows of the table. Persistence entities can be implemented ( similar to a struct in C) or as business objects, including business logic depending on the design specification as a simple data management classes.

Object-relational metadata

The relationships between tables are expressed in terms of object-relational metadata. These are either applied as Java annotations and / or stored in a separate XML file.

The Java Persistence Query Language

Java Persistence Query Language ( JPQL ) is used to perform searches on the data stored in the database entity. These queries are similar syntactically SQL queries, but instead refer to entities to database tables.

The JPA implementations convert formulated in JPQL queries at run time in an SQL statement that is understood by the target database system. Through this abstraction, the database system can be exchanged transparently, while the Java classes are fully preserved. In contrast, JPA also permits the use of "normal" SQL queries, which are referred to as native query. When using Native Queries, however, the user himself must make sure that the query is understood by the target system.

Java Persistence in the context

Many Java developers already used before the advent of the Java Persistence API open source persistence frameworks. This happened mostly on the grounds that the manual implementation of persistence on the basis of Object - relational impedance mismatches should be consuming and error prone. The for the Java Platform, Enterprise Edition to 1.4 Entity Beans are provided by their high consumption of resources, their complexity, and the need to run on a Java EE application server, but too expensive. The possibilities of propagated before the Java Persistence API from SUN Java Data Objects, however, presented the fewest developers.

In developing the Java Persistence API, many properties of the already established open source persistence frameworks such as Hibernate and Toplink flowed. These frameworks offer now partly also implementations of the Java Persistence API.

Java Persistence 3.0 was defined as part of the Enterprise JavaBeans specification and thus provides a successor to the Entity Beans dar. Although the EJB 3.0 specification is part of the Java EE 5 platform, is to use no EJB container or a corresponding Java EE application server needs. Future versions should therefore be defined as a separate Java Community Process outside the EJB specification.

The Java Persistence API was developed for the relational persistence of relatively simple objects. For object databases continue to Java Data Objects or similar frameworks must be dodged. The Service Data Object (SDO ) API, however, is mainly used for mapping of complex data in various formats and programming languages ​​for use in Service Oriented Architectures.

However, the Java Persistence API supports all three types of object-relational mapping inheritance relationships (Table per inheritance hierarchy table per subclass and table-per- concrete class ).

Implementations

The JPA 2.0 specification is supported by a number of persistence frameworks. Among other Apache OpenJPA, Hibernate and Eclipse Link

432187
de