1 2 Previous Next 21 Replies Latest reply on Apr 1, 2011 4:57 AM by Ales Justin

    JBoss 6 & Persitence Archive in WEB-INF/lib

    Vincent A Newbie

      Hello,

      I have a persitence jar that I want other jars in my web-app n(packaged as a war)  to use:

       

      {code}

      my-war

      +--WEB-INF

             +-- lib

                   A.jar

                   persistence.jar

                   Z.jar

      {code}

       

      The persistence unit defined in persistence.jar is injected in Stateless beans in A.jar in Z.jar like so:


      {code}
      @Stateless
      public class ABean {

      @PersistenceContext(unitName =  "my-pu")

        EntityManager em;

      }

       

       

      @Stateless

      public class ZBean {

      @PersistenceContext(unitName =  "my-pu")

        EntityManager em;

      }

       

      {code}

       

      Now, Jboss 6 (I'm using 6.0.0.Final) scans the jars in web-inf/lib in alphabetical order, and tries to locate the persistence unit at load time.

      So,  it fails to scan A.jar because it cannot find the persistence unit (as  persitence.jar hasn't been scanned yet).

      If I remove A.jar, everything works fine because  the persistence unit has been started by the time jboss scans Z.jar.

       

      1) Can a persistence unit defined in a jar under web-inf/lib  be accessed by other jars in web-inf/lib?

      2) If yes, how can I tell jboss to load the PU jar first?

      3) If not, is the solution to perform a jndi look-up to retrieve the entity manager, instead of injecting it?

       

      Thanks,

       

      Vincent

        1 2 Previous Next