11 Replies Latest reply on Dec 10, 2008 12:10 PM by Andrew Rubinger

    EAR Scoped PersistenceUnit

    Maurice Zeijen Master

      Let's say that I create the following package:

      - app.ear
      - /lib
      - pu.jar
      - /META-INF/persistence.xml
      - aEJB3Lib.jar
      - DAOEJB3Lib.jar

      The persistence unit defined in the persistence.xml of /lib/pu.jar should be EAR scoped and not Globally Scoped (using a ear scoped classloader). Am I right? At least I understood this from the documentation. The problem is that in JBoss 4.2.1 it looks like that the persistence unit becomes globally. I will explain what the effects are.

      As you can see I have this DAOEJB3Lib.jar. It contains the entity classes but also some DAO Stateless beans. Those DAO's get there persistence manager using the unit name defined in the persistence.xml of /lib/pu.jar (lets say it is called pu1). I used this construction so that I can reuse those DAO's for different applications. Because the persistence unit name is hard coded in the DAO's of the DAOEJB3Lib.jar lib we need to define the same name in the persistence.xml. This means that if the DAOEJB3Lib.jar is reused by multiple applications on the same server there will also exist multiple persistence units with the same. If the persistence unit is ear scoped then this setup wouldn't create any problems. Practically however this doesn't work.

      All works fine if one application with this DAOEJB3Lib.jar lib is deployed on the server. The problems begin when I deploy a second application that contains the same DAOEJB3Lib.jar. The first application won't work any more because it now retrieves the persistence unit from the second application...

      Did I understand the Documents wrong or is there a Bug in the EJB3.0 lib of JBoss 4.2.1?