Java Persistence API
The Java Persistence API, sometimes referred to as JPA, is a Java programming language framework that allows developers to manage relational data in applications using Java Platform, Standard Edition and Java Platform, Enterprise Edition.
The Java Persistence API originated as part of the work of the JSR 220 Expert Group.
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
Contents |
Entities
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.
See Wikibooks:Java persistence:JPQL.
Relation to Enterprise JavaBeans
The EJB 3.0 specification (itself part of the Java EE 5 platform) included a definition of the Java Persistence API. End-users do not need an EJB container or a Java EE application server in order to run applications that use persistence, however. 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).
Relation to the 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 relational persistence (ORM: Object relational mapping) only for RDBMS (although providers exists who support other datastores). The Java Data Objects specification(s) provides relational persistence (ORM), as well as persistence to other types of datastores.
Relation to the Service Data Object API
The designers[who?] of 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. It is generally accepted[by whom?] that the Java Persistence API is a significant improvement on the EJB 2.0 specification. The Service Data Objects (SDO) API (JSR 235) has a very different objective to the Java Persistence API and is considered[by whom?] 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.
Motivation for creating the Java Persistence API
Many enterprise Java developers use lightweight persistent objects provided by open-source frameworks or Data Access Objects instead of entity beans: 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 2009 projects like Hibernate and Open-Source Version TopLink Essentials have become implementations of the Java Persistence API.
Relation to Hibernate
Hibernate provides an open source object-relational mapping framework for Java. Versions 3.2 and later provide an implementation for the Java Persistence API.[1]
Gavin King founded[2] Hibernate. He represented JBoss on JSR220[3], the JCP expert group charged with developing JPA. This led to ongoing controversy and speculation centered around the relationship between JPA and Hibernate. Sun Microsystems has stated[4] that ideas came from several frameworks, including Hibernate and JDO.
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 planning on supporting JPA 2.0
- Oracle TopLink
- Hibernate
- OpenJPA
See also
External links
- General info
- Video Tutorial
- Documentation
- Implementations
- Amber (Part of Caucho Resin)
- Cayenne
- CocoBase JPA Certified Commercial implementation for standalone and container services
- DataNucleus Access Platform JPA/JDO Certified implementation of Java persistence
- EclipseLink
- Hibernate
- JPOX JPA/JDO Certified implementation of Java persistence (no longer supported - replaced by DataNucleus)
- Kodo
- OpenJPA
- SAP Netweaver Application Server, Java(TM) EE 5 Edition
- SimpleJPA
- TopLink
- JPM2Java Code generator for JPA.
- Frameworks
- Articles
References
- ^ "hibernate.org - Java Persistence with Hibernate". JBoss. http://www.hibernate.org/397.html. Retrieved 2008-11-17. "Hibernate implements the Java Persistence object/relational mapping and persistence management interfaces"
- ^ "Manning: Java Persistence with Hibernate". Manning. http://www.manning.com/bauer2/. Retrieved 2008-11-17. "Gavin King -- 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. http://java.sun.com/javaee/overview/faq/persistence.jsp. Retrieved 2008-11-17. "The Java Persistence API draws upon the best ideas from persistence technologies such as Hibernate, TopLink, and JDO"
|