Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/Composite"

Line 1: Line 1:
 +
= EclipseLink JPA: Composite Persistence Units Example =
 +
 +
Starting with [http://www.eclipse.org/eclipselink/releases/2.3.0.php EclipseLink 2.3.0] JPA developers can now combine persistence units together at runtime allowing entities to be stored in different databases. This includes support for relationships between entities in different persistence units (references across databases). For long time users of TopLink/EclipseLink this feature is an upgrade to the native Session Broker functionality to make it easier to use with JPA.
 +
 +
'''Usage'''
 +
 
* Two or more persistence units could be combined into a single Composite persistence Unit.
 
* Two or more persistence units could be combined into a single Composite persistence Unit.
 
* Each composite members persistence unit keeps mapping its classes to its own database.
 
* Each composite members persistence unit keeps mapping its classes to its own database.
 
** Therefore Composite persistence unit allows to map different entities to different data bases.
 
** Therefore Composite persistence unit allows to map different entities to different data bases.
  
* Below is an example of Composite persistence unit definition.  
+
== Example ==
** compositePu specifies transaction type and server platform.  
+
 
** It contains all persistence units defined in member1.jar and member2.jar files.
+
Below is an example of Composite persistence unit definition. The persistence Unit 'compositePu' specifies transaction type and server platform. It contains all persistence units defined in member1.jar and member2.jar files.
 +
 
 
<source lang="xml">
 
<source lang="xml">
 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">

Revision as of 09:21, 13 June 2011

EclipseLink JPA: Composite Persistence Units Example

Starting with EclipseLink 2.3.0 JPA developers can now combine persistence units together at runtime allowing entities to be stored in different databases. This includes support for relationships between entities in different persistence units (references across databases). For long time users of TopLink/EclipseLink this feature is an upgrade to the native Session Broker functionality to make it easier to use with JPA.

Usage

  • Two or more persistence units could be combined into a single Composite persistence Unit.
  • Each composite members persistence unit keeps mapping its classes to its own database.
    • Therefore Composite persistence unit allows to map different entities to different data bases.

Example

Below is an example of Composite persistence unit definition. The persistence Unit 'compositePu' specifies transaction type and server platform. It contains all persistence units defined in member1.jar and member2.jar files.

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
    <persistence-unit name="compositePu" transaction-type="JTA">
        <provider>
            org.eclipse.persistence.jpa.PersistenceProvider
        </provider>
 
        <jar-file>member1.jar</jar-file>
        <jar-file>member2.jar</jar-file>
 
        <properties>
            <property name="eclipselink.composite-unit" value="true"/>
            <property name="eclipselink.target-server" value="WebLogic_10"/>
        </properties>
    </persistence-unit>
</persistence>

For more information about Composite persistence units please see the design doc.