EclipseLink Solutions Guide for EclipseLink
Release 2.6
  Go To Table Of Contents

Implementing the Solution

This section includes the following tasks:

Task 1: Configure the Composite Persistence Unit

Because the composite persistence unit is a regular persistence element, it requires a persistence.xml file. Example 9-2 illustrates a sample persistence.xml file. Notice that there are no datasource or jdbc properties.

Example 9-2 The persistence.xml File for a Composite Persistence Unit

<persistence xmlns="" xmlns:xsi="" xsi:schemaLocation=" persistence_1_0.xsd" version="1.0">
    <persistence-unit name="compositePu" transaction-type="JTA">
            <property name="eclipselink.composite-unit" value="true"/>
            <property name="" value="WebLogic_10"/>

You can optionally use the <property name="eclipselink.composite-unit" value="true"/> property to identify a persistence unit as a composite persistence unit.

Use the <jar-file> element to specify the JAR files containing the composite member persistence units. The composite persistence unit will contain all the composite member persistence units found in the JAR files specified.

Task 2: Use Composite Persistence Units

You can use a composite persistence unit as you would any other persistence unit; the EntityManager could be injected, as follows:

EntityManagerFactory entityManagerFactory;

EntityManager entityManager;

Or create it manually:

EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("compositePu", properties);

Task 3: Deploy Composite Persistence Units

To deploy multiple persistence units, deploy all of the JAR files (the composite persistence unit and its members) on the same class loader.

  • When deploying to Oracle WebLogic Server, package the JAR files in an EAR file or the WEB-INF/lib folder of a WAR file.

  • When running as a standalone application, add the JAR files to the class path.

For important requirements, see Composite Persistence Unit Requirements.