1 Reply Latest reply on Jun 21, 2012 10:29 PM by Scott Marlow

    Shared top-level Persistence Unit accessed by a module

    Bruno Borges Newbie

      I'm trying to deploy a JAR with a JPA persistence unit to be shared accross several other deployed JARs.

       

      Consider this:

       

      deployments/my-persistence.jar

      deployments/my-camel-route.jar (started with a @Singleton/@Startup bean)

      deployments/my-other-camel-route.jar (same thing)

       

      I'm not using WAR or EAR files, I'm deploying standalone JARs at top-level.

       

      Because of this, I've added a module with all my dependencies, like Apache Camel, Apache ActiveMQ and Spring Framework on a module called:

       

      "com.mycompany.infra"

       

      under modules/com/mycompany/infra/main

       

      When I deploy the my-persistence.jar artifact, the persistence unit is loaded correctly.

      Even the JNDI object, EntityManagerFactory, is created without problems (using the property jboss.entity.manager.factory.jndi.name).

       

      The artifacts for Camel routes, are correctly configured (jboss-deployment-structure.xml) with a dependency for this JBoss infra module, and a simple route works fine, because they don't access classes from the my-persistence.jar. But whenever I start a route that access the EntityManager, I see a ClassNotFoundException, for any Entity.

       

      This is the dependency on the camel-routes artifacts:

       






      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

        <deployment>

        <dependencies>

        <module name="deployment.my-persistence.jar">

          <imports>

            <include path="com/mycompany/persistence*" />

          </module>

          <module name="com.mycompany.infra">

            <imports>

              <include path="META-INF**" />

            </imports>

          </module>

                          </dependencies>

                </deployment>

      </jboss-deployment-structure>

       

      Of course this this is a ClassLoader issue.

       

      If I put the Entity classes in a my-persistence-classes.jar, under my "com.mycompany.infra", and leave only the persistence.xml in a deployable artifact like my-persistence.jar, the persistence unit cannot be loaded, as of Hibernate cannot find the Entity.

       

      It seems that, the only way I could find to have this setup working, was to put this separated JAR ("my-persistence-classes.jar"), and add this JAR to the module.xml of "org.hibernate".

       

      But I'm really looking for an exit here as of course I don't like the idea of messing up with the Hibernate module.

       

      Does anyone have an idea?