7 Replies Latest reply on Nov 14, 2014 1:35 PM by smarlow

    Persistence unit problem in Jboss7.1.1 AS Final

    eramesh.java

      Hi,

       

      When we upgrade our application from Jboss5 to Jboss7.1.1 AS Final, we are getting the below error message in our eclipse console.

       

       

      Caused by: java.lang.IllegalArgumentException: JBAS011470: Persistence unitName was not specified and there are 6 persistence unit definitions in application deployment "XXX.ear".  Either change the application to have only one persistence unit definition or specify the unitName for each reference to a persistence unit.

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

       

      Our persitence.xml having 6 persistence units.

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

       

      Please Advise!

        • 1. Re: Persistence unit problem in Jboss7.1.1 AS Final
          nickarls

          You must use the unitName attribute of the @PersistenceUnit

          • 2. Re: Persistence unit problem in Jboss7.1.1 AS Final
            smarlow

            Try recreating with the nightly build here.  The error is caused by there being multiple persistence unit definitions in the application and an error check that we added.  With the nightly build, the error check has been loosened up.

             

            The error that your seeing can also be worked around, as Nicklas mentioned. 

             

            Scott

            • 3. Re: Persistence unit problem in Jboss7.1.1 AS Final
              eramesh.java

              Hi,

               

              For this issue, we identified the solution.

               

              In standalone.xml file comment the below lines. Issue has been resolved.

               

              <!--subsystem xmlns="urn:jboss:domain:jpa:1.1">

              <jpa default-datasource=""/>

              </subsystem →

               

              Regards,

              Ramesh.E

              • 4. Re: Persistence unit problem in Jboss7.1.1 AS Final
                xidan100

                I've commented out the lines you mentioned from standalone.xml and the app got deployed. However, when it actually tried to fetch records from the database a null pointer exception is thrown because the EntityManager turned out to be null. Any solutions?

                • 5. Re: Re: Persistence unit problem in Jboss7.1.1 AS Final
                  smarlow

                  Another workaround might be to add the persistence unit hint "wildfly.jpa.default-unit" set to "true" in the persistence unit that should be used.  Or update each @PersistenceContext + @PersistenceUnit to specify the persistence unit name in the application.

                   

                  <?xml version="1.0" encoding="UTF-8"?>

                  <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">

                      <persistence-unit name="your_PU">

                      <jta-data-source>java:jboss/datasources/YourDS</jta-data-source>

                   

                  <properties>

                           <property name="wildfly.jpa.default-unit" value="true" /> 

                  </properties>

                  </persistence-unit>

                  </persistence>

                   

                  • 6. Re: Re: Persistence unit problem in Jboss7.1.1 AS Final
                    xidan100

                    Thank you Scott for the quick response. Here're some of the details of my problem:

                     

                    I have this web app in an ear with two EJB modules, each being a persistence unit accessing its own database schema. The persistence.xml(s) located in the META-INF of the EJB jars look like the following:


                    <persistence>   

                    <persistence-unit name="DB1PU" transaction-type="JTA">

                      <jta-data-source>java:jboss/datasources/DB1</jta-data-source>

                      </persistence-unit>

                    </persistence>

                     

                    <persistence>   

                      <persistence-unit name="DB2PU" transaction-type="JTA">

                      <jta-data-source>java:jboss/datasources/DB2</jta-data-source>

                      </persistence-unit>

                    </persistence>

                     

                    The Entity Manager for each EJB module is annotated like this:

                     

                    @PersistenceContext( unitName = "DB1PU")

                    protected EntityManager entityManager1;

                     

                    @PersistenceContext( unitName = "DB2PU")

                    protected EntityManager entityManager2;

                     

                    My app needs to access both schemas so I can't say which one is the default.

                     

                    When I first deployed the ear on jboss-as-7.1.1-final I got the error of "JBAS011470: Persistence unitName was not specified and there are 2 persistence unit definitions in application deployment".

                     

                    Then I tried commenting out the following from standalone.xml:

                    <!--subsystem xmlns="urn:jboss:domain:jpa:1.1">

                    <jpa default-datasource=""/>

                    </subsystem-->

                     

                    It deployed but when it actually tried to fetch records from the database a null pointer exception is thrown because the EntityManager turned out to be null.

                     

                    I've just tried adding the <property name="wildfly.jpa.default-unit" value="true" /> to one of the persistence.xml and uncommenting the jpa subsystem in standalone.xml and got the same JBAS011470 error. Is this property supported in 7.1.1?

                     

                     

                    Please help.

                    • 7. Re: Re: Persistence unit problem in Jboss7.1.1 AS Final
                      smarlow

                       

                      I've just tried adding the <property name="wildfly.jpa.default-unit" value="true" /> to one of the persistence.xml and uncommenting the jpa subsystem in standalone.xml and got the same JBAS011470 error. Is this property supported in 7.1.1?

                      No, but you could also ensure that each use of @PersistenceContext is specifying the unitName.