8 Replies Latest reply on Dec 26, 2012 11:01 AM by nickarls

    multiple persistence units, no default persistence unit?

    lafr

      My 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?

        • 1. Re: multiple persistence units, no default persistence unit?
          smarlow
          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).

           

          In AS7, the persistence unit name does not need to be unique across ear's (applications cannot access the persistence unit of other application deployments).  You should be able to deploy both "prod.ear" and "test.ear" (concurrently) with both using PU name "prim" (pointing to different databases/jdt-data-sources).

          • 2. Re: multiple persistence units, no default persistence unit?
            venkman

            Same Problem here, i tried:

             

            @PersistenceContext(unitName="name")

            EntityManager entityManager;

             

            and:

             

            @PersistenceUnit(unitName="name")

            EntityManagerFactory emf;

            EntityManager entityManager = emf.create...

             

            and even:

             

            @PersistenceUnit(unitName="name")

            EntityManager entityManager;

             

            but still get the above mentioned error... .

             

            I have 5 different named persistence-units pointng to one DB in my ear.

             

            So, how can fix these behaviour?

             

            I'm using 7.1.1.Final

            • 3. Re: multiple persistence units, no default persistence unit?
              smarlow

              Venkman,

               

              Can you try again with the AS7 nightly build?  I'm not 100% sure that you are hitting the same error (you need to show us the exception with the call stack).  If you are hitting the same error, the fix for AS7-4710 might help.

               

              Scott

              • 4. Re: multiple persistence units, no default persistence unit?
                venkman

                Thanks,

                 

                using the 7.2.0.alpha-1 works.

                • 5. Re: multiple persistence units, no default persistence unit?
                  eramesh.java

                  Hi,

                   

                  I am also getting the same error.

                   

                  --------------

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                  16:41:32,890 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC00001: Failed to start service jboss.deployment.unit."ML-PricingEAR.ear".DEPENDENCIES:

                  org.jboss.msc.service.StartException

                  in service jboss.deployment.unit."ML-PricingEAR.ear".DEPENDENCIES: Failed to process phase DEPENDENCIES of deployment "ML-PricingEAR.ear"

                  at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(

                  DeploymentUnitPhaseService.java:119

                  ) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                  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_21]

                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(

                  ThreadPoolExecutor.java:908

                  ) [rt.jar:1.6.0_21]

                  at java.lang.Thread.run(

                  Thread.java:619

                  ) [rt.jar:1.6.0_21]

                  Caused by:

                  java.lang.IllegalArgumentException

                  : JBAS011470: Persistence unitName was not specified and there are 6 persistence unit definitions in application deployment "ML-PricingEAR.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.1.Final.jar:7.1.1.Final]

                  ... 5 more

                  ----------------------

                   

                  Plesae see my persistence.xml content to the above 6 persistence units.

                  ------------------------

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                   

                  <

                   

                  persistence-unit name="pricingRMSRDMEE" transaction-type="JTA"

                  >

                   

                  <provider>org.hibernate.ejb.HibernatePersistence</provider

                  >

                   

                  <jta-data-source>java:jboss/jdbc/pricingRMSRDMDS</jta-data-source

                  >

                   

                  <exclude-unlisted-classes>true</exclude-unlisted-classes

                  >

                   

                   

                  <properties

                  >

                   

                  <property name="hibernate.show_sql" value="false"

                  />

                   

                  <!-- These are the default for JBoss EJB3, but not for HEM: -->

                   

                  <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"

                  />

                   

                  <property name="jboss.entity.manager.factory.jndi.name" value="java:emf/prRMSRDMEm"

                  />

                   

                   

                  <!-- Added for Jboss7 -->

                   

                  <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"

                  />

                   

                  <property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"

                  />

                   

                  </properties

                  >

                   

                  </persistence-unit>

                   

                  ---------------

                   

                  I tried in jboss-as-7.2.0.Alpha1-SNAPSHOT also.  But no luck.

                   

                  Please Advise!

                   

                  • 6. Re: multiple persistence units, no default persistence unit?
                    smarlow

                    The error that you pasted does have "7.1.1" in it.  If you did try again with the nightly/latest AS7 master code and still get the error, you likely have ambigous references to the persistence unit. 

                     

                    Have you tried changing the PersistenceUnits/PersistenceContexts to specify the persistence unit name?  If that is  too complicated, you could separate the packaging for each persistence unit.

                    • 7. Re: multiple persistence units, no default persistence unit?
                      eramesh.java

                      Hi Scott,

                       

                      " Have you tried changing the PersistenceUnits/PersistenceContexts to specify the persistence unit name?  If that is  too complicated, you could separate the packaging for each persistence unit."

                       

                      How to implement this in our code?

                       

                      Please advise!

                      • 8. Re: multiple persistence units, no default persistence unit?
                        nickarls

                        Correction - the time spent googling vs the time spent writing the question in *two* threads.