Community
Participate
Working Groups
To connect the same persistence unit with two different connection parameters (in two different EMFs) the session name should be specified, like: props1.put(PersistenceUnitProperties.SESSION_NAME, "session1"); props1.put(PersistenceUnitProperties.JDBC_USER, "user1"); EMF emf1 = createEMF("default", props1); props2.put(PersistenceUnitProperties.SESSION_NAME, "session2"); props2.put(PersistenceUnitProperties.JDBC_USER, "user2"); EMF emf2 = createEMF("default", props2); // emf1 uses session "session1"; emf2 = "session2". This change enables automatic creation of a new session based on connection properties passed to createEMF. The generated session name is a concatination of unique persistence unit name and connenction properties' names and values: props1.put(PersistenceUnitProperties.JDBC_USER, "user1"); EMF emf1 = createEMF("default", props1); props2.put(PersistenceUnitProperties.JDBC_USER, "user2"); EMF emf2 = createEMF("default", props2); // emf1 uses session "default_user=user1"; emf2 - "default_user=user2". Connection properties used for session name generation are listed in updated EntityManagerSetupImpl: public static String[] connectionPropertyNames = { PersistenceUnitProperties.TRANSACTION_TYPE, PersistenceUnitProperties.JTA_DATASOURCE, PersistenceUnitProperties.NON_JTA_DATASOURCE, PersistenceUnitProperties.JDBC_URL, PersistenceUnitProperties.JDBC_USER, }; There are some changes made to deployment (mostly application managed case - creatEMF): emSetupImpls keyed on session names; puName requires url for uniquiness in the only case of JavaSECMPInitializer without agent (potential app. server case) - for all other cases puName uniquely defines the persistence unit; JPAInitializer.initialize now happens only for JavaSECMPInitializer - only once and only in case agent is used. It (as always) creates and predeploys all the pu it can find, those are now cached in initialEmSetupImpls map; also initialPuInfos map caches their puInfos - forever. The first factory for the persistence unit gets the cached initialEmSetupImpl; all others get the cached initialPuInfo. Added clean up for temp class loaders, globalInstrumentation, not adding transformers after initialization - should eat less memory. JPAInitializer is no longer a singleton. In all other cases there is no initialization - each pu is initialized individually when the factory for it is created; puInfos never shared between emSetupImpls. Instead of initialize the key method now is findPersistenceUnitInfo. After undeployed emSetupImpl is discarded from the emSetupImpls map; Altered a bit states of EntityManagerSetupImpl - now there is no way to get anywhere from UNDEPLOYED state. Also EntityManagerSetupImpl no longer caches properties passed to predeploy - that resolves bug 271066.
Created attachment 150543 [details] Suggested patch.
Checked the patch into trunk.
*** Bug 271066 has been marked as a duplicate of this bug. ***
Created attachment 150667 [details] Correction for standalone SE case (globalInstrumentation != null) This is a small correction affecting only standalone SE case (globalInstrumentation != null). In the original patch initialSetupImpls and initialPuInfos are (stupidly)initialized in JavaSECMPInitializer.initPersistenceUnits method - that means every new resource removes initialSetupImpls and initialPuInfos cached by the previous one - this patch moves initialization of the maps before persistence units loop. Note that the code still worked - just inefficiently didn't reuse initialSetupImpls and initialPuInfos for the bulk of persistence units. Unrelated addition to the same code is verification of uniqueness of persistence unit name: because in standalone SE (globalInstrumentation!=null) case all the persistence units are loaded from the same classloader the puName should uniqueky identify persistence unit (there is no way to distinguish between several persistence units with the same name, loaded on the same classloaader). The new exception specifies puName and two URLs that both use it - that allows user to quickly fix the problem.
Checked in Correction for standalone SE case patch.
Created attachment 150856 [details] Correction 2 for standalone SE case (globalInstrumentation != null) Initialization never happened if postponed until main (-javaagent:eclipselink.jar=main)
Checked into trunk.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink