0 Replies Latest reply on Jun 4, 2015 10:26 AM by Joe Miller

    org.hibernate.MappingException migrating to JBoss 7

    Joe Miller Newbie

      I am migrating two apps from JBoss 5.1 EAP to JBoss AS 7.1.1. The applications have their own databases, but contain many tables that have a common layout. The annotated entity classes for these common tables are d efined in common.jar, which resides in the {jboss.server.home.url}/lib directory, and the entity classes are defined in the application EAR's persistence.xml. Other app-specific entity classes are packaged inside an EJB JAR inside the EAR.

      Since the {jboss.server.home.url}/lib directory directory no longer exists in JBoss7, I want to package common.jar inside the EAR's lib directory, so that the EAR now looks like this:

      app.ear

      /META-INF/

        persistence.xml

        MANIFEST.MF

        application.xml

      /lib/

        common.jar

      app-ejb.jar

      app.war


       

      The persistence unit in persistence.xml is defined as

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

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

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

        <class>com.mycorp.entity.CommonTable1</class>

        <class>com.mycorp.entity.CommonTable2</class>

        <class>com.mycorp.app.entity.AppSpecificTable</class>

        <jar-file>lib/common.jar</jar-file>

        <exclude-unlisted-classes>true</exclude-unlisted-classes>

        <properties>

          <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />

          <property name="hibernate.hbm2ddl.auto" value="validate" />

          <property name="hibernate.show_sql" value="false" />

          <property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/appEntityManagerFactory"/>

        </properties>

      </persistence-unit>


       

      However, when I deploy the app JPA doesn't find my annotated entity classes in common.jar:

      18:17:02,903 TRACE [org.jboss.as.jpa] getClassesInJar url=/content/common.jar annotations=[interface javax.persistence.MappedSuperclass, interface javax.persistence.Entity, interface javax.persistence.Embeddable]

      18:17:02,909 TRACE [org.jboss.as.jpa] No classes to scan for annotations in jar 'vfs:/content/common.jar' (jars with classes '[vfs:/content/app.ear/lib/common.jar/, vfs:/content/app.ear/app-ejb.jar/]')

      18:17:02,910 TRACE [org.jboss.as.jpa] getPackagesInJar url=/content/common.jar annotations=[]

      18:17:02,910 TRACE [org.jboss.as.jpa] No classes to scan for annotations in jar 'vfs:/content/common.jar' (jars with classes '[vfs:/content/app.ear/lib/common.jar/, vfs:/content/app.ear/app-ejb.jar/]')


       

      And this later results in this a "org.hibernate.MappingException: Unknown entity: com.mycorp.entity.CommonTable1" exception.

      I'm assuming this is some sort of classloader problem, but I'm at a loss to figure out how to allow JPA to see my entity classes. Can anybody point me in the right direction? My google-fu has come to naught.

      Thanks,

       

      Joe

       

      Message was edited by: Joe Miller -- formatting.