1 Reply Latest reply on Sep 14, 2006 3:19 AM by Laumond Christophe

    AbstractEntityManagerImpl.persist in Embeddable EJB 3.0 usin

    Laumond Christophe Newbie

      Hi all,

      I'm using Seam 1.0.1GA which means Hibernate as persistence layer.

      I have done a TestNG test for testing my Data Access EJB which are using hibernate using the SeamTest class.
      This means that my Data Access EJB is deployed and my test is accessing it as a Seam component.

      TestNG is using Microcontainer and Embeddable EJB3.

      According to the log trace, the following hibernate version are used :

      Hibernate EntityManager 3.2.0.CR1
      Hibernate Annotations 3.2.0.CR1
      Hibernate 3.2 cr2

      The test is working perfectly when I use the compiled class files directly.

      Then I have packed the classes files in two different jar files :
      - the first contains the Entities
      - the second contains the Data Access Objects using the EntityManager

      I got the following error :

      [testng] ERROR 14-09 09:54:35,609 (Log4JLogger.java:error:119) -persist failed
      [testng] java.lang.IllegalArgumentException: Unknown entity: accountingAudit.businessObjects.Publicationstatus
      [testng] at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:189)
      [testng] at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:175)
      [testng] at accountingAudit.dataAccessObjects.PublicationstatusHome.persist(PublicationstatusHome.java:38)


      my entity in the first jar files

      @Entity
      @Table(name = "publicationstatus", catalog = "accountingaudit", uniqueConstraints = {})
      public class Publicationstatus implements java.io.Serializable {
      ...
      }


      My DAO in the second jar files

      @Stateless
      @Name("publicationstatusDAO")
      @Interceptors(SeamInterceptor.class)
      @Local
      public class PublicationstatusHome implements PublicationStatusLocal {
      
       private static final Log log = LogFactory
       .getLog(PublicationstatusHome.class);
      
       @PersistenceContext(unitName="entityManager")
       private EntityManager entityManager;
      
       public void persist(Publicationstatus transientInstance) {
       log.debug("persisting Publicationstatus instance");
       try {
       entityManager.persist(transientInstance);
       log.debug("persist successful");
       } catch (RuntimeException re) {
       log.error("persist failed", re);
       throw re;
       }
       }
      


      So, obviously this due to the packing in the jar file.

      But I don't know if this is due to a missing Hibernate annotations, an error in the Embeddable EBJ3 or anything else...

      Any help would be greatly appreciate.

      Thanks in advance

      Christophe Laumond,
      M-ITC Ltd,
      Mauritius
      I don't know if the error

        • 1. Re: AbstractEntityManagerImpl.persist in Embeddable EJB 3.0
          Laumond Christophe Newbie

          Thanks to Xavier Hanin which has given me the answer through his website :
          https://izvin.bountysource.com/news/show/98


          hibernate entity manager only scans the classes found in the same ?jar? as the persistence.xml. Since my entity classes are in the common project and my persistence.xml in my desktop project (I will have a different one for my shared service project later), it doesn?t find my entities. So I should either add a jar-file entry to my persistence.xml, but this isn?t really possible for an app deployed on the client by the user. So I?ll have to list my entities here. Mmm, I don?t like that. Fortunately, hibernate offers an extension to the specification and let specify a whole package instead of a single class. Fine, let?s use that feature, I?ll do spec compliant stuff when I?ll want to deploy on another EJB3 container :-)



          and thanks to the JBoss team for the good documentation :
          http://docs.jboss.org/ejb3/app-server/reference/build/reference/en/html_single/index.html


          <persistence>
          <persistence-unit name="manager1">
          <jta-data-source>java:/DefaultDS</jta-data-source>
          <jar-file>../MyApp.jar</jar-file>
          ...



          jar-file and class
          The class element specifies a fully qualified classname that you will belong to the persistence unit. The jar-file element specifies another jar you want automatically scanned for @Entity classes. When using jar-file, you must specify a path relative to the jar file the persistence.xml file is in. By default also, the jar the persistence.xml file is placed in is scanned for @Entity classes as well.