3 Replies Latest reply on Feb 12, 2013 10:07 PM by shay1680

    Hibernate auto detection not working

    shay1680

      Hi,

       

      In a simple test with JPA , hibernate is throwing exceptions due to "Unknown entity" if I rely on auto detection :

       

      <persistence-unit name="EmailTest">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <exclude-unlisted-classes>false</exclude-unlisted-classes>
              <properties>
                  <!-- Scan for annotated classes and Hibernate mapping XML files -->
                  <property name="hibernate.archive.autodetection" value="class" />
      

       

      <property name="hibernate.archive.autodetection" value="class" />

       

      But if I set the the enitty class sepcifically in persistence.xml it works :

       

      <persistence-unit name="EmailTest">
              <provider>org.hibernate.ejb.HibernatePersistence</provider>
              <class>com.project.webea.data.entities.Account</class>
              <exclude-unlisted-classes>false</exclude-unlisted-classes>
              <properties>
                  <!-- Scan for annotated classes and Hibernate mapping XML files -->
                  <property name="hibernate.archive.autodetection" value="class" />
      

       

       

      Which looks like the hibernate auto detection is not working in the Arquillian archive?

       

      Here is my deployment method:

       

      public static WebArchive makeArchive() {
              WebArchive archive = ShrinkWrap.create(WebArchive.class, "test.war")
                      .addAsWebInfResource("beans.xml")
                      .addPackage(Account.class.getPackage())
                      .addAsResource("test-persistence.xml",
                              "META-INF/persistence.xml");
              System.out.println(arc.toString(true));
              return arc;
          }
      

       

      Here is the archive layout:

      test.war:
      /WEB-INF/
      /WEB-INF/beans.xml
      /WEB-INF/classes/
      /WEB-INF/classes/com/
      /WEB-INF/classes/com/projector/
      /WEB-INF/classes/com/projector/webea/
      /WEB-INF/classes/com/projector/webea/data/
      /WEB-INF/classes/com/projector/webea/data/entities/
      /WEB-INF/classes/com/projector/webea/data/entities/Account_.class
      /WEB-INF/classes/com/projector/webea/data/entities/Account.class
      /WEB-INF/classes/META-INF/
      /WEB-INF/classes/META-INF/persistence.xml
      
      

       

      I am using the weld-ee-embedded container

       

      Any suggestions?

       

      Thanks,

        • 1. Re: Hibernate auto detection not working
          aslak

          Only Mocked JPA is availble in weld-ee-embedded. The weld-ee-embedded continer is basically only a CDI contianer with a few mocked EE services and some Context handling.

           

          You'll need to use container that support both specifications, jpa and cdi, e.g. JBoss AS or GlassFish..

           

          What's the stachtrace you're seeing btw? Wondering where the 'HibernateSession' is created.

          • 2. Re: Hibernate auto detection not working
            shay1680

            Hi Aslak,

             

            I am creating the persistence factory and entity manager manually and injecting them, so there is no issue with JPA/Hibernate except for the autodiscovery.

             

            How does arquillian package libraries into the archive or container class path, maybe some hibernate dependency is missing?

             

            here is the stack trace:

             

            java.lang.IllegalArgumentException: Unknown entity: com.project.webea.data.entities.Account

                at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:868)

                at com.project.base.GenericDAO.makePersistent(GenericDAO.java:137)

                at com.project.extendedEM.interceptor.Transactee.createAccount(Transactee.java:17)

                at com.project.extendedEM.interceptor.Transactee$Proxy$_$$_WeldSubclass.createAccount(Transactee$Proxy$_$$_WeldSubclass.java)

             

            Thanks,

            Shay

            • 3. Re: Hibernate auto detection not working
              shay1680

              after chatting on the ARQ IRC and reading some of the online articles , I have decided to drop embedded containers, and stick to remote ones.

               

              Shay