11 Replies Latest reply on Jan 23, 2009 5:58 PM by Julien Kronegg

    javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context

    Leandro Hermida Newbie

      Hi,


      In the Seam Reference docs it describes nicely all the advantages of using Seam-managed transactions and persistence context even in a Java EE 5 environment with EJB 3.0. 


      Following the instructions I defined:


      <transaction:ejb-transaction/>
      
      <persistence:managed-persistence-context name="entityManager"
                                               auto-create="true"
                                               persistence-unit-jndi-name="java:/sysfusionEntityManagerFactory"/>



      in components.xml to enable Seam-managed transactions and to configure the Seam-managed persistence context with JPA.  I also added the following to my persistence unit in persistence.xml:


      <property name="jboss.entity.manager.factory.jndi.name" value="java:/sysfusionEntityManagerFactory"/>



      So based on the reference docs I can use


      @In EntityManager entityManager;



      in my JSF action listener beans.  So as a test I did the Seam registration example shown in the reference docs with all the code the same except instead of


      @PersistenceContext EntityManager entityManager;



      I put


      @In EntityManager entityManager;



      When I try to submit the registration form I get the following error:




      17:01:38,905 ERROR [application] javax.ejb.EJBTransactionRolledbackException: Error performing 'org.sysfusion.core.session.RegisterAction.register()' --> javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress
      ...

        • 1. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
          Leandro Hermida Newbie

          Hello again - just re-reading the Seam references docs carefully and I still don't know what I am doing wrong.


          As the docs state if I use an EJB container-managed persistence context (and use @PersistenceContext EntityManager entityManager) the transaction transparently starts and ends around the session bean method call (e.g. registerAction.register())


          But if I upgrade my persistence context to Seam-managed as I did above (and use @In EntityManager entityManager) it doesn't seem to do anything no by default transparently?  What am I missing?


          leandro

          • 2. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
            Leandro Hermida Newbie

            Hi again everyone,


            My central question which I don't think the docs answer is:


            Does Seam-managed transactions + SMPC in a Java EE 5 environment transparently start and end transactions by default around the session bean method call like the default behavior in CMPC?


            Or do I need to specify things manually?


            thanks for any help,


            leandro

            • 3. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
              Leandro Hermida Newbie

              Anyone have any insight on this?  I am doing everything by the book and I keep getting:



              javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress

              anyone... anyone? Bueller? Bueller? :0)


              leandro

              • 4. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
                Guillaume Jeudy Master

                Leandro,


                Seam managed transactions always creates 2 transactions per request:


                use two transactions per request; the first spans the beginning of the update model values phase until the end of the invoke application phase; the second spans the render response phase


                Your session bean if it executes between these phases should always have an active transaction available thanks for Seam.


                Can I see the code of RegisterAction ? Please explain when register action is invoked when the No Tx exception is thrown.


                • 5. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
                  Leandro Hermida Newbie

                  Hi,


                  Thanks very much for the help I am completely stuck on this one...


                  As you have seen in my other post (here) I have a DAO layer using the Generic DAO pattern where I use SMPC in this layer.  If I use the DAO layer in my JSF action session bean as shown below:



                  @Stateless
                  @Name("registerAction")
                  @Scope(ScopeType.PAGE)
                  public class RegisterActionImpl implements RegisterAction {
                      
                      private User registerUser;
                      
                      @In
                      private UserDAO userDAO;
                  
                      public User getRegisterUser() {
                          if (registerUser == null)
                               registerUser = new User();
                       return registerUser;
                      }
                  
                      public void setRegisterUser(User registerUser) {
                       this.registerUser = registerUser;
                      }
                      
                      public String register() {
                          try {
                              User existingUser = userDAO.findByUsername(registerUser.getUsername());
                              FacesMessages.instance().add("Username #{registerUser.username} already exists");
                              return null;
                       } catch (Exception ex) {
                              if (ex instanceof NoResultException) {
                                 userDAO.create(registerUser);              <-------------- error occurring here!
                                 return "/registered.xhtml";
                           } else {
                               FacesMessages.instance().add("Persistence error: " + ex.getMessage());
                               return null;
                              }
                       }
                      }
                  }



                  I get the following error stack trace on form submission (it's very long...):


                  15:44:36,456 ERROR [application] javax.ejb.EJBTransactionRolledbackException: Error performing 'org.sysfusion.core.session.RegisterAction.register()' --> javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress
                  javax.faces.el.EvaluationException: javax.ejb.EJBTransactionRolledbackException: Error performing 'org.sysfusion.core.session.RegisterAction.register()' --> javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress
                       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
                       at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
                       at javax.faces.component.UICommand.broadcast(UICommand.java:387)
                       at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
                       at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
                       at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
                       at org.ajax4jsf.component.AjaxViewRoot.processApplication(AjaxViewRoot.java:466)
                       at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
                       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                       at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                       at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:44)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:38)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:150)
                       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:267)
                       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:379)
                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:506)
                       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
                       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
                       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
                       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
                       at java.lang.Thread.run(Thread.java:595)
                  Caused by: javax.ejb.EJBTransactionRolledbackException: Error performing 'org.sysfusion.core.session.RegisterAction.register()' --> javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress
                       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
                       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
                       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
                       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:77)
                       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
                       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.localInvoke(StatelessContainer.java:240)
                       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
                       at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
                       at $Proxy139.register(Unknown Source)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                       at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                       at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                       at org.javassist.tmp.java.lang.Object_$$_javassist_3.register(Object_$$_javassist_3.java)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:329)
                       at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:342)
                       at org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
                       at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
                       at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
                       at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
                       at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
                       ... 51 more
                  Caused by: net.sf.fuge.GenericException: Error performing 'org.sysfusion.core.session.RegisterAction.register()' --> javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress
                       at org.sysfusion.core.session.RegisterActionImpl.register(RegisterActionImpl.java:113)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                       at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                       at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                       at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
                       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                       ... 90 more
                  Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
                       at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:293)
                       at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:92)
                       at net.sf.fuge.GenericDAOSeamJPAImpl.create(GenericDAOSeamJPAImpl.java:69)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
                       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
                       at org.jboss.seam.intercept.EJBInvocationContext.proceed(EJBInvocationContext.java:44)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
                       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                       at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
                       at sun.reflect.GeneratedMethodAccessor120.invoke(Unknown Source)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
                       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
                       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
                       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:77)
                       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:110)
                       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
                       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
                       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.localInvoke(StatelessContainer.java:240)
                       at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:210)
                       at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:84)
                       at $Proxy132.create(Unknown Source)
                       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                       at java.lang.reflect.Method.invoke(Method.java:585)
                       at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
                       at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
                       at org.jboss.seam.intercept.ClientSideInterceptor$1.proceed(ClientSideInterceptor.java:76)
                       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
                       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
                       at org.jboss.seam.intercept.ClientSideInterceptor.invoke(ClientSideInterceptor.java:54)
                       at org.javassist.tmp.java.lang.Object_$$_javassist_4.create(Object_$$_javassist_4.java)
                       at org.sysfusion.core.session.RegisterActionImpl.register(RegisterActionImpl.java:104)
                       ... 121 more



                  So from the stack trace what looks the most interesting is at the root cause:


                  Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
                       at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:293)
                       at org.jboss.seam.persistence.EntityManagerProxy.flush(EntityManagerProxy.java:92)
                       at net.sf.fuge.GenericDAOSeamJPAImpl.create(GenericDAOSeamJPAImpl.java:69)
                          ...



                  which is the entityManager.flush() method in my Generic DAO layer in GenericDAOSeamJPAImpl.java.  Here is the code:



                  public abstract class GenericDAOSeamJPAImpl<T, ID extends Serializable>
                       implements GenericDAO<T, ID> {
                  
                      private Class<T> entityClass;
                  
                      @In
                      protected javax.persistence.EntityManager entityManager;
                      
                      ...
                       
                      /**
                       * @see net.sf.fuge.GenericDAO#create(T)
                       */
                      @SuppressWarnings( { "unchecked" })
                      public T create(final T entity) 
                              throws IllegalArgumentException, GenericException {
                          if (entity == null) {
                              throw new IllegalArgumentException(entityClass.getSimpleName() + ".create - 'entity' cannot be null");
                          }
                          
                          try {
                              entityManager.persist(entity);
                              entityManager.flush();                <------- root error occurring here!!!
                              return entity;
                          } catch (Exception ex) {
                              throw new GenericException(ex);
                       }
                      }
                      
                      ...
                  
                  }



                  I believe I have a pretty standard DAO layer so what am I doing wrong?


                  leandro


                  • 6. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
                    Leandro Hermida Newbie

                    Sorry forgot something that you might find important.  The error line in my console just after the whole error stack trace above:


                    15:56:42,776 ERROR [lifecycle] JSF1054: (Phase ID: INVOKE_APPLICATION 5, View ID: /userRegister.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@58b942f7]


                    • 7. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
                      Guillaume Jeudy Master

                      The error you are hitting is I think due to EJB3 exception handling.


                      You are catching a NoResultException which is a runtime exception. By default EJB3 handles RuntimeException as system exception which means unrecoverable. The EJB3 container will rollback any active transaction if it sees a RuntimeException thrown out of an EJB3 business method.


                      What you want to do is wrap the NoResultException and rethrow it as a checked exception. Checked exceptions are treated as ApplicationException and by default the EJB3 container doesnt rollback the transaction but will let the caller handle the exception as it is considered recoverable.


                      • 8. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
                        Leandro Hermida Newbie

                        Hi,


                        Gosh I wouldn't have ever seen that... for quite a few of my queries I use getSingleResult() underneath which can return NoResultException and I was expecting that but I was catching it and throwing my checked GenericException(ex) which accidentally extends from RuntimeException so that wasn't helping. 



                        public User findByUsername(final String username) throws GenericException {
                            try {
                                javax.persistence.Query queryObject = entityManager.createNamedQuery("User.findByUsername");
                                queryObject.setParameter("username", username);
                                Object result = queryObject.getSingleResult();
                                return (User) result;
                            } catch (Exception ex) {
                                throw new GenericException(ex);
                            }
                        }




                        By changing my thrown GenericException to extend from Exception instead then it doesn't silently rollback the transaction!


                        Do you have any advice on Exception design with respect to the Generic DAO pattern I mentioned and in the JSF session beans?  It what I am doing (in my DAOs and SBs) orthodox?


                        thanks a lot!


                        leandro

                        • 9. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
                          Guillaume Jeudy Master

                          Exceptions shouldnt be used for workflow control, they should only be used to handle exceptional conditions. If you expect this findByUsername method to fail to find a user on normal workflow condition then my advice is not to use exceptions.


                          What you could do is swallow the NoResultException and return null from findByUserName. The caller would know that if no user name is found (null returned) it has to create a new user.

                          • 10. Re: javax.ejb.EJBTransactionRolledbackException: javax.persistence.TransactionRequiredException: no transaction is in progress in Java EE 5 with Seam-managed transactions and persistence context
                            Enrico Goosen Newbie

                            Hi,


                            I read your other post:



                            Generic DAO pattern with Seam-managed transactions and SMPC doesn't work

                            ...but from this thread it appears that you managed to get it working.


                            I'm also trying to implement the Generic DAO pattern using SMPC, but I'm getting a ClassCastException here:


                            public BaseJPADAO() {
                                 this.type = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
                            }


                            It appears that I'm not the only one experiencing this problem:
                            See this thread


                            Here's my code:


                            public interface BaseDAO<T extends Serializable, PK extends Serializable> {
                            }


                            public class BaseJPADAO<T extends BaseEntity, PK extends Serializable> implements BaseDAO<T, PK> {
                            }


                            public interface TblUserDAO extends BaseDAO<TblUser, Integer> {
                            }


                            public class TblUserJPADAO extends BaseJPADAO<TblUser, Integer> implements TblUserDAO {
                            }


                            Any help/advice/suggestions?


                            Regards,
                            Enrico