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

Introduction to the Solution

With a composite persistence unit, you can:

Example 9-1 shows how you can persist data from a single persistence context into two different databases:

Example 9-1 Using Multiple Databases

em.persist(new A(..));
em.persist(new B(..));
// You can insert A into database1 and insert B into database2.
// The two databases can be from different vendors.


Figure 9-1 illustrates a simple composite persistence unit. EclipseLink processes the persistence.xml file and detects the composite persistence unit, which contains two composite member persistence units:

Figure 9-1 A Simple Composite Persistence Unit

Description of Figure 9-1 follows
Description of "Figure 9-1 A Simple Composite Persistence Unit"

Composite Persistence Unit Requirements

When using composite persistence units, note the following requirements:

  • The name of each composite member persistence unit must be unique within the composite.

  • The transaction-type and other properties that correspond to the entire persistence unit (such as target server, logging, transactions, and so on) should be defined in the composite persistence unit. If not, the transaction types, target server information, and logging properties defined with composite members will be ignored.