3 Replies Latest reply on Nov 9, 2011 7:17 AM by Jens Mander

    Issue with entity classes in different jar-file (persistence.xml)?

    Jens Mander Newbie

      Hi,

       

      I have an application where the business logic is seperated from the entity classes by putting them into differend jar files. I have the following structure of the ear-file:

       

      Thunder-ear.ear

        |

        + Thunder-ejb.jar

        |

        + lib

           |

          + Thunder-entity.jar

       

      The persistence.xml resides in the Thunder-ejb.jar and looks like that:

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.0"
         xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
              http://java.sun.com/xml/ns/persistence
              http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
          <persistence-unit name="primary">
            <!-- Use this for AS7 -->
            <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
      
            <!-- Use this for AS6 -->
            <!--<jta-data-source>jdbc/__default</jta-data-source>-->
              <jar-file>lib/Thunder-entity.jar</jar-file>
              <properties>
               <!-- Properties for Hibernate -->
                  <!--<property name="jboss.as.jpa.providerModule" value="org.hibernate:3"/>-->
                  <property name="hibernate.hbm2ddl.auto" value="create-drop" />
                  <property name="hibernate.show_sql" value="false" />
              </properties>
          </persistence-unit>
      </persistence>
      
      

       

      My tiny test application just tries to persist and load an entity like that:

       

      package com.sample.thunder.bean;
      
      import com.sample.thunder.entity.Song;
      /* Import stuff */
      
      @Singleton
      @Startup
      public class ThunderBean {
      
          @PersistenceContext
          EntityManager em;
      
          Logger LOG;
      
          @PostConstruct
          void persistAndLoad() {
              LOG = getLogger();
      
              // Hibernate does not find the entity classes
              em.persist(new Song(42L, "Lightning"));
              LOG.info("Entity persisted");
              em.flush();
              Song e = em.find(Song.class, 42L);
              LOG.info("Entity found: " + e);
      
              Song s = new Song(42L, "Thunder");
              LOG.info(s.toString());
          }
          // ...
      }
      
      

       

      This tiny test application works absolutely fine on AS6 but fails on AS7.0.2 with:

       

      Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: Unknown entity: com.sample.thunder.entity.Song
                at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:160)
                at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:213)
                at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:313)
                at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:56)
                at org.jboss.as.ejb3.tx.SingletonLifecycleCMTTxInterceptor.processInvocation(SingletonLifecycleCMTTxInterceptor.java:42)
                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)
                at org.jboss.as.ejb3.component.session.SessionInvocationContextInterceptor.processInvocation(SessionInvocationContextInterceptor.java:71)
                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)
                at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45)
                at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:287)
                at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
                at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:152)
      
      

       

      Okay Hibernate can not find the entity class. But why? I specified where to find it in the persistence.xml. The dependency between the both jars seems to be ok because if I'm commenting out the whole persistence stuff it's no problem to create an instance of "Song".

      My first guess after checking my whole setup was a issue in Hibernate 4 so I configured a Hibernate 3 module in AS7 and put in the dependency to it but that didn't solve the problem. So I guess I missed out to specify something somewhere to let Hiberante know how to find the entity classes. Unfortunalely I don't have any clue what to do anymore. May anybody help me solving this issue?

       

      Best regards

       

      Sascha