2 Replies Latest reply on Apr 20, 2009 6:46 AM by Dave Oxley

    Help, please - StaleObjectStateException!

    Dave Oxley Newbie

      I am creating a record using EntityHome.persist and adding a transaction success event:


      events.raiseTransactionSuccessEvent("processTransactionSuccess", context);


      In the processTransactionSuccess method I'm then starting a thread which immediately updates the newly created record. The below exception is then thrown in the original thread. Can anyone please tell me how I fix this and what I could possibly be doing wrong?


      Thanks,
      Dave.


      19 Apr 2009 21:38:26,246 ERROR lushingEventListener - Could not synchronize database state with session
      org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.daveoxley.Test#1]                                                                                                                                                                       
              at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1792)                                                                   
              at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2435)                                                                  
              at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)                                                          
              at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)                                                                  
              at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)                                                                                      
              at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)                                                                                                    
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)                                                                                             
              at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)                                                                                             
              at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)                                                   
              at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)                                                                      
              at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)                                                                                                       
              at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)                                                                                                 
              at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)                                                                                        
              at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)                                                                                                 
              at org.jboss.seam.transaction.EntityTransaction.commit(EntityTransaction.java:110)                                                                                   
              at org.jboss.seam.jsf.SeamPhaseListener.commitOrRollback(SeamPhaseListener.java:614)                                                                                 
              at org.jboss.seam.jsf.SeamPhaseListener.handleTransactionsAfterPageActions(SeamPhaseListener.java:352)                                                               
              at org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:571)                                                                                    
              at org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:473)                                                                             
              at org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:146)                                                                               
              at org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:116)                                                                                      
              at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:214)                                                                                                   
              at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:96)                                                                                                              
              at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)                                                                                              
              at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)                                                                                                    
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)                                                                 
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)                                                                         
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:532)                                                                                                      
              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.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630)                                                                             
              at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)                                                                     
              at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)                                                                          
              at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)                                                                            
              at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195)                                                                       
              at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159)                                                                                     
              at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)                                                                                           
              at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)                                                                                 
              at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)                                                                            
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)                                                                 
              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.web.RewriteFilter.doFilter(RewriteFilter.java:63)                                                                                                  
              at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)                                                                                    
              at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)                                                                                                
              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.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)                                                                                    
              at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)                                                                                             
              at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)                                                                                                 
              at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)                                                                                
              at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)                                                                                                      
              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.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)                                                                               
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)                                                                               
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)                                                                            
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)                                                                                     
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)                                                                                     
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)                                                                                 
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)                                                                                       
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)                                                                                        
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)                                                                  
              at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)                                                                                           
              at java.lang.Thread.run(Thread.java:619)                                                                                                                             


        • 1. Re: Help, please - StaleObjectStateException!
          Dave Oxley Newbie

          I should also mention that the original thread no longer has a reference to the entity object after the processTransactionSuccess method and just attempts to redisplay the current page by returning null from the action method. The action method has:


          @End(beforeRedirect=true)



          And the class is defined as:


          @Scope(ScopeType.CONVERSATION)



          There is an init action method defined in pages.xml:


              <page view-id="/test.xhtml" action="#{test.init}">
                  <param name="testId" value="#{testSelectionService.selectedId}"/>
              </page>



          This method does some reads and initialises some fields on the page.


          I'm using Seam 2.1.1.GA. Please ask if further info is required.


          Thanks,
          Dave.

          • 2. Re: Help, please - StaleObjectStateException!
            Dave Oxley Newbie

            I've just realised I shouldn't even be getting a StaleObjectStateException as I'm using a JPA entitymanager. I'm beginning to think this must be a bug in Hibernate or Seam.