multiple persistence units, no default persistence unit?
lafr Apr 2, 2012 6:22 PMMy ear contains to ejb-modules containing, each of them including a persistence.xml file pointing to different databases.
ejb-entity.jar is the first file, zzz-entity.jar the last one in application.xml, multiple session bean jars inbetween. zzz-entity.jar only contains the persistence.xml.
Using JBoss 4.2x and 6.x with deployment in the order of the application xml this was working perfect.
All session beans used the entity bean jar listed before.
No session bean uses the the persistence unit declared in zzz-entity.jar per injection.
It's only used programmatcally in a session bean with Persistence.createEntityEntityManagerFactory( "xxx" ) etc.
Now using 7.1.2.Final-SNAPSHOT I get an error messages like:
23:08:48,691 INFO [org.jboss.as.jpa#parse] JBAS011401: Read persistence.xml for prod
23:08:49,069 INFO [org.jboss.as.jpa#parse] JBAS011401: Read persistence.xml for prod-ems
23:08:49,269 ERROR [org.jboss.msc.service.fail#startFailed] MSC00001: Failed to start service jboss.deployment.subunit."prod.ear"."ejb-session-inventory.jar".DEPENDENCIES: org.jboss.msc.service.StartException in service jboss.deployment.subunit."prod.ear"."ejb-session-inventory.jar".DEPENDENCIES: Failed to process phase DEPENDENCIES of subdeployment "ejb-session-inventory.jar" of deployment "prod.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.2.Final-SNAPSHOT.jar:7.1.2.Final-SNAPSHOT]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_31]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_31]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_31]
Caused by: java.lang.IllegalArgumentException: JBAS011470: Persistence unitName was not specified and there are 2 persistence unit definitions in application deployment "prod.ear". Either change the application to have only one persistence unit definition or specify the unitName for each reference to a persistence unit.
at org.jboss.as.jpa.container.PersistenceUnitSearch.resolvePersistenceUnitSupplier(PersistenceUnitSearch.java:69)
at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getPersistenceUnit(JPAAnnotationParseProcessor.java:284)
at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.getBindingSource(JPAAnnotationParseProcessor.java:220)
at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processField(JPAAnnotationParseProcessor.java:151)
at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.processPersistenceAnnotations(JPAAnnotationParseProcessor.java:118)
at org.jboss.as.jpa.processor.JPAAnnotationParseProcessor.deploy(JPAAnnotationParseProcessor.java:90)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.2.Final-SNAPSHOT.jar:7.1.2.Final-SNAPSHOT]
... 5 more
The problem is, that the persistence unit name is not constant. So I cannot put it into the code.
I deploy my ear several times under different names, e.g. prod.ear and test.ear.
prod.ear then also has "prod" as the primary PU name and test.ear has "test" as the primary PU name.
Additionally "prod-ems" and "test-ems" as their secondary PU name in zzz-entity.jar.
As far as I know, it's necessary to make the PU name unique across ear's.
Meaning I cannot have prod.ear with PU "prim" and test.ear with PU "prim" at the same time, pointing to different databases (jta-data-source's).
Is there anyway to get the behaviour as in the versions prior to 7.x?
Or any other idea how to solve this?