1 Reply Latest reply on Jul 1, 2005 5:45 PM by Alan Berezin

    newbie having problems with ejb3 EntityManager

    Alan Berezin Newbie

      I am running jboss-4.0.1sp1 with the ejb3 preview under 1.5.0_02. I have a simple webapp running and am trying to use the EJB3 CMP from within a DAO pattern. Everything is running in the same vm and Im using the built in hypersonic db.

      Once I startup jboss, my EJB deploys ok (at least, there are no exceptions thrown and nothing logged at the INFO level to indicate a problem). Have also deployed the Entity tutorial and from ANT, can make it run so I think the running jboss is configured correctly.

      Here is the code I have problems with:

      import javax.ejb.Inject;
      import javax.persistence.EntityManager;
      import com.dmd.ratecalc.LoanCalculation;
      
      public class LoanCalculatorDao {
       @Inject
       private EntityManager manager;
      
       public void store(LoanCalculation lc) throws Exception {
       manager.persist(lc);
       }
      }
      


      Stepping through the store(..) method, the manager field is null (I am running under eclipse but I have tried to run outside eclipse and get the same null prt exception).

      Any ideas? Below is some of the console output:


      15:21:48,821 INFO [Ejb3Module] found EJB3 Entity bean: com.dmd.ratecalc.LoanCalculation
      15:21:49,571 INFO [Ejb3Module] EJB3 deployment time took: 1578
      15:21:49,603 INFO [Ejb3Module] EJB3 jar using default hibernate.properties: {hibernate.transaction.manager_lookup_class=org.hibernate.transaction.JBossTransactionManagerLookup, hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider, hibernate.dialect=org.hibernate.dialect.HSQLDialect, hibernate.hbm2ddl.auto=create-drop, hibernate.connection.datasource=java:/DefaultDS, hibernate.query.factory_class=org.hibernate.hql.ast.ASTQueryTranslatorFactory}
      15:21:52,134 INFO [EJB3Deployer] Deployed: file:/C:/jboss-4.0.1sp1/server/all/deploy/dmd.ejb3




        • 1. Re: newbie having problems with ejb3 EntityManager
          Alan Berezin Newbie

          I could make it work by creating a stateless session bean like the tutorial does like:

           InitialContext ctx = new InitialContext();
           LoanCalculatorDaoLocal c = (LoanCalculatorDaoLocal) ctx.lookup(LoanCalculatorDaoLocal.class.getName());
           c.store(lc);
          


          However, I would like to make it work with a simpler DAO pattern where the DAO calls manager.persist(..). That is what I cannot get to work. It is not clear to me if the session bean pattern is needed to use the entity bean and if so, why it needs to be that way.