Chapter 3. EclipseLink JPA Persistence Provider

The Java Persistence API (JPA) is a component of EJB 3.0 and replaces CMP and JDO. Oracle's strategic Java persistence implementation within Oracle Fusion Middleware 11g is Oracle TopLink 11g, which is based on the open source EclipseLink. EclipseLink is based on an older version of TopLink, which Oracle contributed to Eclipse. The EclipseLink version in Oracle Fusion Middleware 11g supports the JPA 1.0 specification. In this chapter, we shall discuss the JPA framework and the EclipseLink JPA persistence provider.

What is a JPA persistence provider? A JPA persistence provider is an implementation of the JPA; JPA is just a specification. Various JPA persistence providers such as Hibernate, Apache OpenJPA, and JPA for WebSphere Application Server are available, but we shall be discussing the persistence provider in Oracle Fusion Middleware: the EclipseLink JPA persistence provider. This section is not meant to be a repetition of the JPA specification (http://jcp.org/en/jsr/detail?id=220), or the EclipseLink JPA documentation (http://wiki.eclipse.org/Category:JPA), but a primer and an introduction to some of the features/values used in this book. In this chapter, we shall discuss the following:

  • How to specify the EclipseLink persistence provider?
  • The JPA framework
    • The advantages of JPA
    • What is required for JPA?
  • Types of Entity Managers
    • Container-managed entity manager
    • Application-managed entity manager
  • EclipseLink JPA
    • Metadata annotations
    • XML mapping metadata
    • Entity identity
    • Entity relationships
  • EclispeLink JPA persistence unit properties

Specifying the EclipseLink persistence provider

The minimum required configuration to start using the EclipseLink persistence provider is to specify the persistence provider in the configuration file persistence.xml. The persistence provider is specified in the META-INF/persistence.xml configuration file in the provider sub-element of the persistence-unit element.

<?xml version="1.0" encoding="Cp1252" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="em">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/app/jdbc/jdbc/OracleDBConnectionDS</jta-data-source>
<class>model.Catalog</class>
<properties>
...
</properties>
</persistence-unit>
</persistence>