3 Replies Latest reply on May 28, 2011 12:01 AM by smarlow

    EntityManager injection Failure with Multiple persistence-unit of Jboss6

    zhang.hongyu

      hi,  I got a problem when inject the EntityManagar in Jboss 6.0.0.  we have two persistence-unit defined in the persistence.xml which are

       

       

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

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

      ...

         </persistence-unit>

       

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

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

      ...

         </persistence-unit>

       

      The  persistence-unit will be injected in two Stateless bean like

       

      Class A {

          @PersistenceUnit(unitName="PU1")

          private EntityManagerFactory emf;

       

       

       

          public String getEMInfo(){

              /* PersistanceUnit name is mapped as "hibernate.session_factory_name" */

              return emf.getProperties().toString();

          }

       

       

       

      }

       

       

      Class B {

          @PersistenceUnit(unitName="PU2")

          private EntityManagerFactory emf;

       

          public String getEMInfo(){

              /* PersistanceUnit name is mapped as "hibernate.session_factory_name" */

              return emf.getProperties().toString();

          }

       

      }

       

      Everything is packed in one EAR file and the depoly was successful without error. Howerver when I invoke getEMInfo() from both bean it give me the same result!  It shows the injected EntityManagerFactory are bound with PU1.   How can I fix this?

       

      And  the output result changed after re-depoly! sometime to PU1, sometime to PU2