7 Replies Latest reply on Aug 30, 2006 1:09 PM by Samuel Mendenhall

    TransactionException: Could not register synchronization bug

    Samuel Mendenhall Apprentice

      I have inexplicably ran into this exception:
      java.lang.RuntimeException: org.hibernate.TransactionException: Could not register synchronization

      16:20:46,188 ERROR [[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
      javax.faces.FacesException: Error calling action method of component with id _id0:_id57_0:_id61
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
       at javax.faces.component.UICommand.broadcast(UICommand.java:106)
       at javax.faces.component.UIData.broadcast(UIData.java:338)
       at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
       at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
       at org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:316)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:106)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{groupViewer.view}
       at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
       at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:63)
       ... 25 more
      Caused by: java.lang.RuntimeException: org.hibernate.TransactionException: Could not register synchronization
       at org.jboss.ejb3.stateful.StatefulBeanContext.remove(StatefulBeanContext.java:273)
       at org.jboss.ejb3.AbstractPool.remove(AbstractPool.java:171)
       at org.jboss.ejb3.cache.simple.SimpleStatefulCache.remove(SimpleStatefulCache.java:299)
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:89)
       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.stateful.StatefulContainer.localInvoke(StatefulContainer.java:188)
       at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
       at $Proxy210.view(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.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
       ... 26 more
      Caused by: org.hibernate.TransactionException: Could not register synchronization
       at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:159)
       at org.hibernate.ejb.EntityManagerImpl.close(EntityManagerImpl.java:59)
       at org.jboss.ejb3.stateful.StatefulBeanContext.closeExtendedPCs(StatefulBeanContext.java:284)
       at org.jboss.ejb3.stateful.StatefulBeanContext.remove(StatefulBeanContext.java:268)
       ... 44 more
      Caused by: javax.transaction.RollbackException: Already marked for rollback TransactionImpl:XidImpl[FormatId=257, GlobalId=localhost/44, BranchQual=, localId=44]
       at org.jboss.tm.TransactionImpl.registerSynchronization(TransactionImpl.java:635)
       at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:156)
       ... 47 more
      




      I was on a page viewing my groups trying to click on a group which the pages.xml intercepts and calls viewGroup.view.


      pages.xml:
      <pages>
       <page view-id="/viewGroup.jsp" action="#{groupViewer.view}" />
      </pages>
      



      GroupViewerBean.java
      @Name("groupViewer")
      @Stateful
      @Scope(ScopeType.SESSION)
      public class GroupViewerBean implements GroupViewer {
      
       @RequestParameter
       private Long groupId;
      
       private Long id;
      
       @Logger
       private Log log;
      
       @PersistenceContext(type=EXTENDED)
       private EntityManager em;
      
       @Out(required=true)
       Group group;
      
       public String view() {
       Map<String, Object> parameters = new HashMap<String, Object>();
       Query query = em.createQuery("from Group where group.id = :id");
       parameters.put("id", groupId);
      
       for (Entry <String, Object> param : parameters.entrySet()) {
       query.setParameter( param.getKey(), param.getValue() );
       }
       group = (Group) query.getSingleResult();
       return "/viewGroup.seam";
       }
      
       @Destroy @Remove
       public void destroy() {}
      }
      



      Any ideas what could cause this Exception? I have other Stateful beans I'm using no problem.

        • 1. Re: TransactionException: Could not register synchronization
          Samuel Mendenhall Apprentice

          Also, this occurs on a fresh start of JBoss and thereafter, it is not random.

          • 2. Re: TransactionException: Could not register synchronization
            Gavin King Master

            Look in the log or use your debugger to find the real underlying error. There is a bug in EJB3 which hides the true cause of the failure.

            • 3. Re: TransactionException: Could not register synchronization
              Samuel Mendenhall Apprentice

              What is the EJB3 bug and is there a work around? I do not use an IDE, so I won't be able to debug it at the moment.

              The server.log was not very helpful, though it gave a little more information, nothing additional on the exception though:

              2006-08-30 08:43:31,146 DEBUG [org.jboss.seam.util.Naming] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
              2006-08-30 08:43:31,147 DEBUG [org.jboss.seam.Component] instantiating Seam component: org.jboss.seam.core.manager
              2006-08-30 08:43:31,147 DEBUG [org.jboss.seam.core.Manager] Found conversation id in request parameter: 4
              2006-08-30 08:43:31,147 DEBUG [org.jboss.seam.core.Manager] Restoring conversation with id: 4
              2006-08-30 08:43:31,148 DEBUG [org.jboss.seam.contexts.Contexts] found in application context: org.jboss.seam.core.init
              2006-08-30 08:43:31,148 DEBUG [org.jboss.seam.jsf.AbstractSeamPhaseListener] After restoring conversation context: ConversationContext(4)
              2006-08-30 08:43:31,148 DEBUG [org.jboss.seam.util.Naming] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
              2006-08-30 08:43:31,149 DEBUG [org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener] beginning transaction prior to phase: RENDER_RESPONSE(6)
              2006-08-30 08:43:31,149 DEBUG [org.jboss.seam.util.Naming] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
              2006-08-30 08:43:31,150 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolving name: groupViewer
              2006-08-30 08:43:31,150 DEBUG [org.jboss.seam.Component] instantiating Seam component: groupViewer
              2006-08-30 08:43:31,150 DEBUG [org.jboss.seam.util.Naming] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
              2006-08-30 08:43:31,151 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.HeirarchicalLoaderRepository3@112ee4f, cl=org.jboss.mx.loading.HeirarchicalLoaderRepository3$CacheClassLoader@32835b{ url=null ,addedOrder=0}
              2006-08-30 08:43:31,154 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.HeirarchicalLoaderRepository3@112ee4f, cl=org.jboss.mx.loading.HeirarchicalLoaderRepository3$CacheClassLoader@4df9a0{ url=null ,addedOrder=0}
              2006-08-30 08:43:31,160 DEBUG [org.hibernate.impl.SessionImpl] opened session at timestamp: 4738833658511360
              2006-08-30 08:43:31,160 DEBUG [org.hibernate.jdbc.JDBCContext] TransactionFactory reported no active transaction; Synchronization not registered
              2006-08-30 08:43:31,160 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
              2006-08-30 08:43:31,160 DEBUG [org.hibernate.jdbc.JDBCContext] successfully registered Synchronization
              2006-08-30 08:43:31,166 DEBUG [org.jboss.seam.jsf.SeamVariableResolver] resolved name to seam component
              2006-08-30 08:43:31,170 DEBUG [org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor] ++++ LongLivedSessionPropagationInterceptor
              2006-08-30 08:43:31,170 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Looking for a JTA transaction to join
              2006-08-30 08:43:31,170 DEBUG [org.hibernate.ejb.AbstractEntityManagerImpl] Transaction already joined
              2006-08-30 08:43:31,172 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.HeirarchicalLoaderRepository3@112ee4f, cl=org.jboss.mx.loading.HeirarchicalLoaderRepository3$CacheClassLoader@1654886{ url=null ,addedOrder=0}
              2006-08-30 08:43:31,172 DEBUG [org.jboss.seam.interceptors.RemoveInterceptor] Stateful component was removed: groupViewer
              2006-08-30 08:43:31,177 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[bug-tracker].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
              javax.faces.el.EvaluationException: Exception while invoking expression #{groupViewer.view}
               at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:153)
               at org.jboss.seam.core.Pages.callAction(Pages.java:161)
               at org.jboss.seam.core.Pages.callAction(Pages.java:143)
               at org.jboss.seam.jsf.AbstractSeamPhaseListener.callPageActions(AbstractSeamPhaseListener.java:128)
               at org.jboss.seam.jsf.AbstractSeamPhaseListener.beforeRender(AbstractSeamPhaseListener.java:98)
               at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:50)
               at org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener.beforePhase(SeamExtendedManagedPersistencePhaseListener.java:38)
               at org.apache.myfaces.lifecycle.LifecycleImpl.informPhaseListenersBefore(LifecycleImpl.java:520)
               at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:342)
               at javax.faces.webapp.FacesServlet.service(FacesServlet.java:107)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
               at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
               at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
               at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
               at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
               at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
               at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
               at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
               at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
               at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
               at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
               at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
               at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
               at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
               at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
               at java.lang.Thread.run(Thread.java:595)
              Caused by: java.lang.RuntimeException: org.hibernate.TransactionException: Could not register synchronization
               at org.jboss.ejb3.stateful.StatefulBeanContext.remove(StatefulBeanContext.java:273)
               at org.jboss.ejb3.AbstractPool.remove(AbstractPool.java:171)
               at org.jboss.ejb3.cache.simple.SimpleStatefulCache.remove(SimpleStatefulCache.java:299)
               at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:89)
               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.stateful.StatefulContainer.localInvoke(StatefulContainer.java:188)
               at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:98)
               at $Proxy144.view(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.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:129)
               ... 27 more
              Caused by: org.hibernate.TransactionException: Could not register synchronization
               at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:159)
               at org.hibernate.ejb.EntityManagerImpl.close(EntityManagerImpl.java:59)
               at org.jboss.ejb3.stateful.StatefulBeanContext.closeExtendedPCs(StatefulBeanContext.java:284)
               at org.jboss.ejb3.stateful.StatefulBeanContext.remove(StatefulBeanContext.java:268)
               ... 45 more
              Caused by: javax.transaction.RollbackException: Already marked for rollback TransactionImpl:XidImpl[FormatId=257, GlobalId=localhost.com/22, BranchQual=, localId=22]
               at org.jboss.tm.TransactionImpl.registerSynchronization(TransactionImpl.java:635)
               at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:156)
               ... 48 more
              


              • 4. Re: TransactionException: Could not register synchronization
                hdslkf hklsdg Apprentice

                RollbackException: Already marked for rollback.

                Do you call setRollbackOnly() somewhere in your code?

                • 5. Re: TransactionException: Could not register synchronization
                  Samuel Mendenhall Apprentice

                  I don't touch transactions in my code anywhere. Here is a strange thing. I take the type=EXTENDED off of my persistence context, and I get a NullPointerException on:

                  Query query = em.createQuery("from Group where group.id = :id");
                  


                  Which tells me that the EntityManager is somehow not getting injected via the @PersistenceContext? HOWEVER, I have another @Stateful bean which has similar functionality, and it is working find. Why is this one being ornery?

                  • 6. Re: TransactionException: Could not register synchronization
                    Samuel Mendenhall Apprentice

                    For reference:

                    persistence.xml

                    <persistence>
                     <persistence-unit name="entityManager">
                     <provider>org.hibernate.ejb.HibernatePersistence</provider>
                     <jta-data-source>java:/DefaultDS</jta-data-source>
                     <properties>
                     <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                     <property name="hibernate.show_sql" value="true"/>
                     <property name="hibernate.format_sql" value="true" />
                     <!--<property name="hibernate.jdbc.batch_size" value="0" />-->
                     <property name="jboss.entity.manager.factory.jndi.name" value="java:/issuesEntityManagerFactory"/>
                     </properties>
                     </persistence-unit>
                    </persistence>
                    


                    components.xml
                    <components>
                    
                     <component name="org.jboss.seam.core.init">
                     <property name="myFacesLifecycleBug">@myFacesLifecycleBug@</property>
                     <property name="jndiPattern">@jndiPattern@</property>
                     </component>
                    
                     <component name="org.jboss.seam.core.manager">
                     <property name="conversationTimeout">120000</property>
                     </component>
                    
                     <component name="entityManager" class="org.jboss.seam.core.ManagedPersistenceContext">
                     <property name="persistenceUnitJndiName">java:/issuesEntityManagerFactory</property>
                     </component>
                    
                     <component class="org.jboss.seam.core.Ejb"
                     installed="@embeddedEjb@"/>
                    
                    </components>
                    


                    • 7. Re: TransactionException: Could not register synchronization
                      Samuel Mendenhall Apprentice

                      Its times like these I want to cry....then laugh really hard, as always Gavin was right, it was in my code.

                      The entire problem has to do in this line:

                      Query query = em.createQuery("from Group where group.id = :id");
                      



                      I left out the group alias, so hibernate has no idea what group.id means. It should be:

                      Query query = em.createQuery("from Group group where group.id = :id");