Java Persistence API
Encyclopedia
The Java Persistence API, sometimes referred to as JPA, is a Java programming language
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

 framework
Software framework
In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by user code, thus providing application specific software...

 managing relational data in applications using Java Platform, Standard Edition
Java Platform, Standard Edition
Java Platform, Standard Edition or Java SE is a widely used platform for programming in the Java language. It is the Java Platform used to deploy portable applications for general use...

 and Java Platform, Enterprise Edition
Java Platform, Enterprise Edition
Java Platform, Enterprise Edition or Java EE is widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier...

.

The Java Persistence API originated as part of the work of the JSR
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....

 220 Expert Group. JPA 2.0 is the work of the JSR
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....

 317 Expert Group.

Persistence
Persistence (computer science)
Persistence in computer science refers to the characteristic of state that outlives the process that created it. Without this capability, state would only exist in RAM, and would be lost when this RAM loses power, such as a computer shutdown....

 in this context covers three areas:
  • the API
    Application programming interface
    An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...

     itself, defined in the javax.persistence package
  • the Java Persistence Query Language
    Java Persistence Query Language
    The Java Persistence Query Language is a platform-independent object-oriented query language defined as part of the Java Persistence API specification.JPQL is used to make queries against entities stored in a relational database...

     (JPQL)
  • object/relational metadata

History

The final release date of the JPA 1.0 specification was 11 May 2006. The JPA 2.0 specification was released 10 Dec, 2009. JPA is a replacement for the much criticized EJB 2.0 and EJB 2.1
Enterprise JavaBean
Enterprise JavaBeans is a managed, server-side component architecture for modular construction of enterprise applications.The EJB specification is one of several Java APIs in the Java EE specification. EJB is a server-side model that encapsulates the business logic of an application...

 entity beans.

Entities

A persistence entity is a lightweight Java class whose state is typically persisted to a table in a relational database
Relational database
A relational database is a database that conforms to relational model theory. The software used in a relational database is called a relational database management system . Colloquial use of the term "relational database" may refer to the RDBMS software, or the relational database itself...

. 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
Java annotation
An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated...

, or in a separate XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

 descriptor file distributed with the application.

The Java Persistence Query Language

The Java Persistence Query Language
Java Persistence Query Language
The Java Persistence Query Language is a platform-independent object-oriented query language defined as part of the Java Persistence API specification.JPQL is used to make queries against entities stored in a relational database...

 (JPQL) makes queries against entities stored in a relational database. Queries resemble SQL
SQL
SQL is a programming language designed for managing data in relational database management systems ....

 queries in syntax, but operate against entity objects rather than directly with database tables.

See Wikibooks:Java persistence:JPQL.

Motivation for creating the Java Persistence API

Many enterprise Java developers use lightweight persistent objects provided by open-source frameworks or Data Access Object
Data Access Object
In computer software, a data access object is an object that provides an abstract interface to some type of database or persistence mechanism, providing some specific operations without exposing details of the database. It provides a mapping from application calls to the persistence layer...

s instead of entity beans
Entity Bean
An Entity Bean is a type of Enterprise JavaBean, a server-side J2EE component, that represents persistent data maintained in a database. An entity bean can manage its own persistence or can delegate this function to its EJB Container . An entity bean is identified by a primary key...

: entity beans and enterprise beans had a reputation of being too heavyweight and complicated, and one could only use them in Java EE application servers. Many of the features of the third-party persistence frameworks were incorporated into the Java Persistence API, and as of 2006 projects like Hibernate
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

 (version 3.2) and Open-Source Version TopLink Essentials
TopLink
In computing, TopLink is an object-relational mapping package for Java developers. It provides a framework for storing Java objects in a relational database or for converting Java objects to XML documents....

 have become implementations of the Java Persistence API.

Enterprise JavaBeans

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
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....

 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 those APIs support the Java Persistence API.

The Java Persistence API specifies relational persistence (ORM: Object relational mapping
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...

) only for RDBMS (although providers exist who support other datastores). The Java Data Objects
Java Data Objects
Java Data Objects is a specification of Java object persistence. One of its features is a transparency of the persistent services to the domain model. JDO persistent objects are ordinary Java programming language classes ; there's no requirement for them to implement certain interfaces or extend...

 specification(s) provides relational persistence (ORM), as well as persistence to other types of datastores.

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
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...

 tools such as Hibernate
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

 and TopLink
TopLink
In computing, TopLink is an object-relational mapping package for Java developers. It provides a framework for storing Java objects in a relational database or for converting Java objects to XML documents....

. Java Persistence API improved on and replaced EJB 2.0, evidenced by its inclusion in EJB 3.0. The Service Data Objects
Service Data Objects
Service Data Objects is a technology that allows heterogeneous data to be accessed in a uniform way. The SDO specification was originally developed in 2004 as a joint collaboration between BEA and IBM and approved by the Java Community Process...

 (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 architecture
Service-oriented architecture
In software engineering, a Service-Oriented Architecture is a set of principles and methodologies for designing and developing software in the form of interoperable services. These services are well-defined business functionalities that are built as software components that can be reused for...

s, multiple data formats rather than only relational data, and multiple programming languages. The Java Community Process
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....

 manages the Java version of the SDO API; the C++
C++
C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

 version of the SDO API is managed via OASIS
Oasis
In geography, an oasis or cienega is an isolated area of vegetation in a desert, typically surrounding a spring or similar water source...

.

Hibernate

Hibernate
Hibernate (Java)
Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

 provides an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 object-relational mapping
Object-relational mapping
Object-relational mapping in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language...

 framework for Java
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...

. Versions 3.2 and later provide an implementation for the Java Persistence API.

Gavin King founded Hibernate. He represented JBoss
JBoss (company)
JBoss is a division of Red Hat, Inc.. It specializes in open-source middleware software.The company profits from a service-based business model. JBoss employ a Professional Open Source business model where the core developers of projects make a living and offer their services...

 on JSR220, the JCP
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....

 expert group charged with developing JPA. This led to ongoing controversy and speculation surrounding the relationship between JPA and Hibernate. Sun Microsystems
Sun Microsystems
Sun Microsystems, Inc. was a company that sold :computers, computer components, :computer software, and :information technology services. Sun was founded on February 24, 1982...

 has stated
that ideas came from several frameworks, including Hibernate and JDO
Java Data Objects
Java Data Objects is a specification of Java object persistence. One of its features is a transparency of the persistent services to the domain model. JDO persistent objects are ordinary Java programming language classes ; there's no requirement for them to implement certain interfaces or extend...

.

JPA 2.0

Development of a new version of JPA, namely JPA 2.0 JSR 317 was started in July 2007. JPA 2.0 was approved as final on December 10, 2009.

The focus of JPA 2.0 was to address features that were present in some of the popular ORM vendors but couldn't gain consensus approval for JPA 1.0.

The main features included in this update are:
  • Expanded object/relational mapping functionality
    • support for collections of embedded objects
    • multiple levels of embedded objects
    • ordered lists
    • combinations of access types
  • A criteria query API
  • standardization of query 'hints'
  • standardization of additional metadata to support DDL generation
  • support for validation


Vendors supporting JPA 2.0
  • DataNucleus
    DataNucleus
    DataNucleus is an open source project which provides a series of software products around data management in Java....

     (formerly JPOX)
  • EclipseLink
    EclipseLink
    EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, Object XML mapping , and Enterprise Information Systems...

     (formerly Oracle TopLink
    TopLink
    In computing, TopLink is an object-relational mapping package for Java developers. It provides a framework for storing Java objects in a relational database or for converting Java objects to XML documents....

    )
  • JBoss Hibernate
    Hibernate (Java)
    Hibernate is an object-relational mapping library for the Java language, providing a framework for mapping an object-oriented domain model to a traditional relational database...

  • ObjectDB
    ObjectDB
    ObjectDB is an Object Database for Java. It can be used in client-server mode and in embedded mode.Unlike other object databases, ObjectDB does not provide its own proprietary API. Accordingly, working with ObjectDB requires using one of the two standard Java APIs - JPA or JDO...

  • OpenJPA
  • IBM
    IBM
    International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...

    , via its OpenJPA-based Feature Pack for OSGi Applications and JPA 2.0 for WebSphere Application Server

See also

  • JDBC
  • JPQL
  • iBATIS
    IBATIS
    iBATIS is a persistence framework which automates the mapping between SQL databases and objects in Java, .NET, and Ruby on Rails. In Java, the objects are POJOs . The mappings are decoupled from the application logic by packaging the SQL statements in XML configuration files...

  • pureQuery
  • OpenXava
    OpenXava
    OpenXava is a web application framework for developing business applications in an effective way. It not only allows rapid and easy development of CRUD modules and report generation, but also provides flexibility to develop complex real life business applications like accounting packages, customer...

  • SAP NetWeaver Application Server
  • JOPS

General info


Documentation


Tutorials

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK