This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 328404 - JPA Persistence Unit Composition
Summary: JPA Persistence Unit Composition
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL: http://wiki.eclipse.org/EclipseLink/D...
Whiteboard:
Keywords:
: 260258 269213 (view as bug list)
Depends on:
Blocks: 260258 280949
  Show dependency tree
 
Reported: 2010-10-21 16:18 EDT by Andrei Ilitchev CLA
Modified: 2022-06-09 10:21 EDT (History)
2 users (show)

See Also:


Attachments
Suggested patch. (1.29 MB, patch)
2011-04-26 18:48 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Slightly updated patch. (1.30 MB, patch)
2011-04-27 14:53 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Patch to fix composite persistence unit static weaving (36.83 KB, patch)
2011-05-04 17:22 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Correction to static weaving patch (17.64 KB, patch)
2011-05-09 15:07 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Patch for composite member using sessions.xml (4.05 KB, patch)
2011-05-10 19:34 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Patch Eclipse jpa tests launch files. (10.96 KB, patch)
2011-05-11 11:01 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Added support for connection properties for composite member persistence unit. (428.46 KB, patch)
2011-05-16 18:55 EDT, Andrei Ilitchev CLA
no flags Details | Diff
The previous patch - corrected (430.73 KB, patch)
2011-05-17 11:41 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Patch adds @CompositeMember annotation and xml support. (22.97 KB, patch)
2011-05-17 19:57 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Small assorted fixes (55.97 KB, patch)
2011-05-19 22:17 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Patch for composite dead connection failover. (15.92 KB, patch)
2011-05-20 16:30 EDT, Andrei Ilitchev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Ilitchev CLA 2010-10-21 16:18:50 EDT
Support SessionBroker in Eclipselink JPA as a first class citizen. SessionBroker should be easy for the user to configure using just custom Eclipselink jpa (annotations, xml, properties).
Comment 1 Andrei Ilitchev CLA 2011-04-26 18:48:04 EDT
Created attachment 194115 [details]
Suggested patch.

Composite persistence unit is defined;

Implemented using SessionBroker, therefore lots of changes in jpa core and tests to substitute ServerSession everywhere to DatabaseSessionImpl (from which both ServerSession and SessionBroker are derived);

Lot of changes in queries to use getExecutionSession() instead of getSession() - that makes difference only in SessionBroker case;

Refactored AbstractSession.getQuery method and overriding methods in derived classes;

For testing copied most of jpa.advanced. and xml.jpa.advanced classes and diveded them between three member persistence units.
Then attempted to copy jpa.advanced.EntityManagerJUnitTestSuite and make it use the new composite persistence unit.
The same was done with jpa.xml.advanced.EntityMappingsAdvancedJUnitTestCase, which used (as the original test) with two persistence unit configurations: one with mapping files; another - extended - with mapping files and eclipselik-orm.xml.

Many tests can run with composite persistence units, some not, some (not too many) may be adapted to run in the future.

To run the tests in full glory the user should specify in their test.properties two additional sets of connection properties to be used by the two last member sessions (the first member session uses supplied connection parameters in TestingBrowser or original connection properties in test.properties:
db.driver=oracle.jdbc.OracleDriver
db.url=jdbc:oracle:thin:@ottvm030.ca.oracle.com:1521:TOPLINK 
db.user=ailitche
db.pwd=password
db.platform=org.eclipse.persistence.platform.database.OraclePlatform

the new properties:

db2.driver=com.ibm.db2.jcc.DB2Driver
db2.url=jdbc:db2://ottvm046.ca.oracle.com:50000/TOPLINK2
db2.user=dev1
db2.pwd=password
db2.platform=org.eclipse.persistence.platform.database.DB2Platform

db3.driver=com.mysql.jdbc.Driver
db3.url=jdbc:mysql://ottvm045.ca.oracle.com:3306/qa3
db3.user=qa3
db3.pwd=password
db3.platform=org.eclipse.persistence.platform.database.MySQLPlatform

If the user does not specify db2 and db3 properties there will be a boolean property, which allows all three member sessions to use the same connection parameters.
Comment 2 Andrei Ilitchev CLA 2011-04-27 14:53:15 EDT
Created attachment 194194 [details]
Slightly updated patch.

Updated properties' names - now all of them prefixed with "eclipselink.composite-unit".
Updated some tests.
Comment 3 Andrei Ilitchev CLA 2011-04-27 15:23:07 EDT
Checked in the updated patch into trunk.

If a bunch of new tests fail with connection exceptions,
make sure to specify property
single.db=true
in your test.properties file or system properties.
In that case all composite members will use the same default data base.

Otherwise specify db2.* and db3.* properties.
For details see eclipselink.jpa.test\test.properties
and / or
org.eclipse.persistence.testing.framework.junit.JUnitTestCaseHelper class.

The new tests are:
org.eclipse.persistence.testing.tests.jpa.composite.advanced.EntityManagerJUnitTestSuite
and
org.eclipse.persistence.testing.tests.jpa.xml.composite.advanced.EntityMappingsAdvancedJUnitTestCase

The latter test could run with to different persistence units (using the same classes): "xml-composite-advanced" and "xml-extended-composite-advanced" (which uses eclipselink-orm.xml).
By default "xml-composite-advanced" is used.
Specify -Dorm.testing=eclipselink to use "xml-extended-composite-advanced".

Note that because both pus use the same classes they should never both appear on the same classpass.

"xml-composite-advanced" defined in
eclipselink-xml-composite-advanced-model.jar
and has members
eclipselink-xml-composite-advanced-model-member_1.jar
eclipselink-xml-composite-advanced-model-member_2.jar
eclipselink-xml-composite-advanced-model-member_3.jar

"xml-extended-composite-advanced" defined in
eclipselink-xml-extended-composite-advanced-model.jar
and has members
eclipselink-xml-extended-composite-advanced-model-member_1.jar
eclipselink-xml-extended-composite-advanced-model-member_2.jar
eclipselink-xml-extended-composite-advanced-model-member_3.jar

Usually the default one ("xml-composite-advanced") is run with all other tests in TestingBrowser (CMP3TestAllRunModel) or FullRegressionTestSuite and the extended one is run separately.
Comment 4 Andrei Ilitchev CLA 2011-05-02 14:34:04 EDT
*** Bug 260258 has been marked as a duplicate of this bug. ***
Comment 5 Andrei Ilitchev CLA 2011-05-04 17:22:37 EDT
Created attachment 194772 [details]
Patch to fix composite persistence unit static weaving
Comment 6 Andrei Ilitchev CLA 2011-05-04 17:37:03 EDT
Checked the patch into trunk.
EntityManagerSetupImpl.predeploy method now used for static weaving, too.
In this case StaticWeaveClassTransformer is set into emSetupImpl to indicate that predeploy will be used for static weaving, also passes logging parameters.
Also fix to allow persistebce unit to read sessionBroker from sessions.xml.
Note that such persistence unit is NOT a composite.
Comment 7 Andrei Ilitchev CLA 2011-05-09 15:07:00 EDT
Created attachment 195129 [details]
Correction to static weaving patch

- Following Tom's review introduced a new class to be passed to EntityManagerSetupImpl (instead of StaticWeaveClassTransformer);
- Corrected problem with static weaving in case sessions.xml is used.
Comment 8 Andrei Ilitchev CLA 2011-05-09 16:39:31 EDT
Checked the patch into trunk.
Comment 9 Andrei Ilitchev CLA 2011-05-10 19:34:45 EDT
Created attachment 195288 [details]
Patch for composite member using sessions.xml

A simple patch in EntityManagerSetupImpl class: composite persistence unit always uses its puName as session name. However SESSION_NAME specified in properties should be used to read correct session from sessions.xml.
Comment 10 Andrei Ilitchev CLA 2011-05-10 21:01:47 EDT
Checked the patch into trunk.
Comment 11 Andrei Ilitchev CLA 2011-05-11 11:01:26 EDT
Created attachment 195368 [details]
Patch Eclipse jpa tests launch files.

Test only patch: added to Eclipse jpa test launch files composite models' jars.
Comment 12 Andrei Ilitchev CLA 2011-05-11 11:07:25 EDT
Checked the patch into trunk.
Comment 13 Andrei Ilitchev CLA 2011-05-16 11:47:15 EDT
*** Bug 269213 has been marked as a duplicate of this bug. ***
Comment 14 Andrei Ilitchev CLA 2011-05-16 18:55:11 EDT
Created attachment 195796 [details]
Added support for connection properties for composite member persistence unit.

In the same way as PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES used to pass member-specific properties to createEMF method now is possible to pass connection properties (to be processed by members) to createEM method.
Tests are in composite.advanced.EntityManagerJUnitTestSuite:
testConnectionPolicy;
testConnectionPolicySetProperty;
testNonPooledConnection;
testExclusiveIsolatedLeaksConnectionOnClear.
Comment 15 Andrei Ilitchev CLA 2011-05-17 11:41:49 EDT
Created attachment 195882 [details]
The previous patch - corrected

After James' review corrected EntityManagerImpl class.
Note that lots of formatting changes in composite.advanced.EntityManagerJUnitTestSuite were done to make as close as possible to the original class advanced.EntityManagerJUnitTestSuite

Ideally all the tests found in the latter should be copied to the former (some adaptation may be required).
Comment 16 Andrei Ilitchev CLA 2011-05-17 11:59:09 EDT
Checked the patch into trunk (revision: 9399).
Comment 17 Andrei Ilitchev CLA 2011-05-17 19:57:19 EDT
Created attachment 195925 [details]
Patch adds @CompositeMember annotation and xml support.

A CompositeMember annotation is ignored unless is in composite member persistence unit.  
It may be used in conjunction with a ElementCollection and CollectionTable annotations.  
It should be used if target type is a primitive type and CollectionTable designates the table that belongs to composite member persistence unit other than the source composite member persistence unit.
That allows the source and target to be mapped to different databases.
Comment 18 Andrei Ilitchev CLA 2011-05-18 10:54:10 EDT
Checked the patch into trunk (rev. 9409). Reviewed by Guy.
Comment 19 Andrei Ilitchev CLA 2011-05-19 22:17:14 EDT
Created attachment 196177 [details]
Small assorted fixes

Even in JPA case composite should not require jpa data source (members do);
Clear JPAQueries on SessionBroker.initializeDescriptors after they copied processed;
Some test fixes.
Comment 20 Andrei Ilitchev CLA 2011-05-19 22:21:19 EDT
Checked the patch into trunk.
Comment 21 Andrei Ilitchev CLA 2011-05-20 16:30:43 EDT
Created attachment 196251 [details]
Patch for composite dead connection failover.

The patch fixes composite reconnection on communication error code, adapts the relevant tests from advanced.EntityManagerJUnitTestSuite.
Comment 22 Andrei Ilitchev CLA 2011-05-20 16:32:28 EDT
Checked the patch into trunk.
Comment 23 Eclipse Webmaster CLA 2022-06-09 10:21:43 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink