1 Reply Latest reply on Jun 24, 2006 5:35 AM by Nicolas Jouanin

    Problem with EAR and PersistenceContext in Jboss 4.0.4GA

    Nicolas Jouanin Newbie

      Hi,

      I'm currently trying to migrate from Jboss 4.0.4RC1 to 4.0.4 GA, and I have some problems with EJB3 stuffs migration.
      I followed the migration wiki pages, but i still have a problem when using EntityManager from stateless beans ; it seems that the persistence context is not found correctly.
      Here's my application structure:
      entities.jar includes entitities POJO + persistence.xml
      sessions.jar includes stateless EJB

      Both files are packaged in a ear file.

      in my stateless bean i have:

      @PersistenceContext(unitName="escapeKRepository")
      protected static EntityManager em;
      


      where escapeKRepository is the name of the persistence-unit. All this was working well with 4.0.4RC1, but now I get :

      Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
       at org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:149)
       at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:174)
      


      when i first call a bean method.
      I read on the wiki pages that there was a special syntax to use in PersistenContext when persistence is not in the same jar, but i don't know how to do it ...
      To be sure, i tried to create a new jar file containing all my classes (POJO + EJB) and the persistence.xml : this worked fine !!

      So , how should i write the @PersistenceContext ?

        • 1. Re: Problem with EAR and PersistenceContext in Jboss 4.0.4GA
          Nicolas Jouanin Newbie

          Well, may be i went too fast.
          Putting all classes in the same jar file didn't solve the problem.
          When i first call a EJB-method which performs a persist to the EntityManager i get :

          javax.ejb.EJBException: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
           at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:69)
           at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:83)
           at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:197)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:78)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:47)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:225)
           at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
           at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
           at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:828)
           at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:681)
           at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:358)
           at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:412)
           at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:239)
          Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
           at org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:149)
           at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:174)