1 Reply Latest reply on May 26, 2009 8:35 AM by ermes martino

    Is it possible to use Hibernate persistent classes from EJB

    ermes martino Newbie

      Hi all,
      I have an Enterprise application made up of a :

      -WAR archive
      -HAR archive (Hibernate persistent classes)

      now I'm going to add an EJB JAR (A Session Bean). I'm trying to use Hibernate persistent classes from the EJB however I've found some problems:

      @Stateless
      public class ManagerBean implements ManagerLocal {
      
       @PersistenceUnit(unitName="unit1") SessionFactory factory;
      
       public void executeQuery() {
      
       // Factory is correctly injected here
       System.out.println("Factory is "+factory);
      
       // TransactionException
       // hsession.beginTransaction();
      
       Session hsession = factory.openSession();
      
       List <Data> result = hsession.createQuery("from com.igv.Data").list();
      
       .....
      }


      The first problem I've met is that I cannot start a Transaction using Hibernate otherwise JBoss issues "javax.ejb.EJBException: org.hibernate.TransactionException: Could not register synchronization for container transaction".

      This is I guess because the EJB is container managed transaction so I cannot use an external transaction manager. Ok.

      Commenting that line however leads to another problem:

      08:55:27,982 WARN [QuerySplitter] no persistent classes found for query class: from com.igv.Data


      So my question is: can you actually use Hibernate persistent classes from an EJB or do you need to port Hibernate classes to Entity Beans ?
      Thanks
      Marco