This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 260258 - Add JPA EntityManagerFactoryBroker support
Summary: Add JPA EntityManagerFactoryBroker support
Status: CLOSED DUPLICATE of bug 328404
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P5 enhancement with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
Depends on: 328404
Blocks:
  Show dependency tree
 
Reported: 2009-01-07 09:40 EST by Doug Clarke CLA
Modified: 2022-06-09 10:24 EDT (History)
5 users (show)

See Also:


Attachments
EntityManager/Session Broker code and test compatible with JPA (1.87 MB, application/x-zip-compressed)
2010-04-29 11:01 EDT, Sebastien Tardif CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Doug Clarke CLA 2009-01-07 09:40:54 EST
Add support for using SessionBroker within EclipseLink JPA. This involves enhancements to the core runtime as well as support for configuration using either native XML or JPA (annotations + ORM.XML).

For the JPA usage case it would be great to bootstrap by specifying multiple persistence units that should be used to create a single PU with a broker. Alternatively we could provide support for defining a broker PU that lists the PU's to be contained.
Comment 1 Tom Ware CLA 2009-04-16 11:05:43 EDT
Updating priority due to revised bug categorization process.  See the following page for details:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines#Priority_and_Target_Milestone 

If you feel the updated priority is incorrect, please send an email to eclipselink-users@eclipse.org.
Comment 2 Doug Clarke CLA 2009-12-18 14:27:38 EST
I believe this should be changed to creating JPA (EMF/EM) broker scenario instead of trying to wire the existing SessionBroker under EMF. Changing the title to reflect this.

Since each persistence unit contains its own data source connectivity info the EMF broker will need to sit above this level of configuration. Setting up a bootstrap API that takes multiple PU specifications is one option but it lacks the ability to be used in container managed mode. Additionally the configuration of mappings between entities in different PUs is challenging.

PROPOSAL: EMF brokers are defined using a 'special' configuration based on standard persistence.xml persistence unit properties.  

EXAMPLE (persistence.xml):

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	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 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
	<!--
		Example of what a persistence.xml might look like configured as a
		broker.
	-->

	<!--
		This PU represents an annotation based configuration. Since the PU's
		might be located in the same packaging unit the classes are listed so
		we don't accidentally get entities from pu-2. The
		exclude-unlisted-classes is set to true to avoid the default discovery
	-->
	<persistence-unit name="pu-1" transaction-type="JTA">
		<jta-data-source>jdbc/PU1</jta-data-source>
		<class>model.Entity1</class>
		<class>model.Entity2</class>
		<exclude-unlisted-classes>true</exclude-unlisted-classes>
	</persistence-unit>

	<!--
		This PU represents an orm.xml based configuration. Since the PU's
		might be located in the same packaging unit the classes are listed so
		we don't accidentally get entities from pu-1. The
		exclude-unlisted-classes is set to true to avoid the default discovery
	-->
	<persistence-unit name="pu-2" transaction-type="JTA">
		<jta-data-source>jdbc/PU2</jta-data-source>
		<mapping-file>META-INF/pu-2-orm.xml</mapping-file>
		<exclude-unlisted-classes>true</exclude-unlisted-classes>
	</persistence-unit>

	<persistence-unit name="broker-pu" transaction-type="JTA">
		<!--
			This mapping file contains the additional mappings that augment what
			is in the individual PUs adding relationships across PU boundaries
		-->
		<mapping-file>META-INF/broker-orm.xml</mapping-file>
		<properties>
			<property name="eclipselink.broker.persistence-units" value="pu-1,pu-2" />
		</properties>
	</persistence-unit>

</persistence>


Issues<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
	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 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
	<!--
		Example of what a persistence.xml might look like configured as a
		broker.
	-->

	<!--
		This PU represents an annotation based configuration. Since the PU's
		might be located in the same packaging unit the classes are listed so
		we don't accidentally get entities from pu-2. The
		exclude-unlisted-classes is set to true to avoid the default discovery
	-->
	<persistence-unit name="pu-1" transaction-type="JTA">
		<jta-data-source>jdbc/PU1</jta-data-source>
		<class>model.Entity1</class>
		<class>model.Entity2</class>
		<exclude-unlisted-classes>true</exclude-unlisted-classes>
	</persistence-unit>

	<!--
		This PU represents an orm.xml based configuration. Since the PU's
		might be located in the same packaging unit the classes are listed so
		we don't accidentally get entities from pu-1. The
		exclude-unlisted-classes is set to true to avoid the default discovery
	-->
	<persistence-unit name="pu-2" transaction-type="JTA">
		<jta-data-source>jdbc/PU2</jta-data-source>
		<mapping-file>META-INF/pu-2-orm.xml</mapping-file>
		<exclude-unlisted-classes>true</exclude-unlisted-classes>
	</persistence-unit>

	<persistence-unit name="broker-pu" transaction-type="JTA">
		<!--
			This mapping file contains the additional mappings that augment what
			is in the individual PUs adding relationships across PU boundaries
		-->
		<mapping-file>META-INF/broker-orm.xml</mapping-file>
		<properties>
			<property name="eclipselink.broker.persistence-units" value="pu-1,pu-2" />
		</properties>
	</persistence-unit>

</persistence>

Pros:
- standard JPA config thus allowing container usage
- relatively straight forward

Cons:
- need to ensure property is processed before orm xml in broker PU
- critical config left to a property thus breaking in other JPA providers
- multiple PUs in same persistence.xml not well supported by current JAP tooling solutions

NEXT STEP: I would like to propose working on this as an incubator effort. I would like to have some other volunteer as contributors and testers before heading down that road.
Comment 3 Sebastien Tardif CLA 2010-04-29 11:01:22 EDT
Created attachment 166498 [details]
EntityManager/Session Broker code and test compatible with JPA

The code included is used in production for a year in a JTA transaction scenario. The test case use explicit transaction management.

Broker implement JPA interface, so this version of broker code is for JPA 1.0.

The layers are design so that most of the code can be reuse unchanged by other implementation of O-R framework like Hibernate.

Please comment. We are looking to integrate improvement.
Comment 4 Andrei Ilitchev CLA 2011-05-02 14:34:04 EDT

*** This bug has been marked as a duplicate of bug 328404 ***
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:14:37 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:24:14 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink