8 Replies Latest reply on Jul 17, 2007 1:00 PM by matt.drees

    StaleStateException from entity activation

    matt.drees

      Hi,

      I'm getting the following exception in a test of mine. The FacesRequest previous to it ended a nested conversation, and also updated the entity in question. I'm not sure if this is my problem or Seam's. Any ideas? Thanks!

      org.hibernate.StaleStateException: current database version number does not match passivated version number
       at org.jboss.seam.persistence.HibernatePersistenceProvider.checkVersion(HibernatePersistenceProvider.java:174)
       at org.jboss.seam.persistence.HibernatePersistenceProvider.checkVersion(HibernatePersistenceProvider.java:134)
       at org.jboss.seam.contexts.PassivatedEntity.checkVersion(PassivatedEntity.java:133)
       at org.jboss.seam.contexts.PassivatedEntity.getEntityFromEntityManager(PassivatedEntity.java:118)
       at org.jboss.seam.contexts.PassivatedEntity.toEntityReference(PassivatedEntity.java:73)
       at org.jboss.seam.contexts.EntityBean.activate(EntityBean.java:67)
       at org.jboss.seam.contexts.ServerConversationContext.unflush(ServerConversationContext.java:234)
       at org.jboss.seam.contexts.FacesLifecycle.resumeConversation(FacesLifecycle.java:129)
       at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:373)
       at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:211)
       at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
       at org.jboss.seam.mock.BaseSeamTest$Request.restoreViewPhase(BaseSeamTest.java:706)
       at org.jboss.seam.mock.BaseSeamTest$Request.emulateJsfLifecycle(BaseSeamTest.java:544)
       at org.jboss.seam.mock.BaseSeamTest$Request.run(BaseSeamTest.java:487)
       at org.uscm.crs.registration.CustomQuestionsAdmin.recreateCustomQuestions(CustomQuestionsAdmin.java:200)
       at org.uscm.crs.registration.CustomQuestionsAdmin.adminCreatingQuestions(CustomQuestionsAdmin.java:101)
       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.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:645)
       at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:479)
       ...
       at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)
      


       cid = new FacesRequest(expectedEditPage, cid) {
      
       @Override
       protected void updateModelValues() throws Exception {
       assert Manager.instance().isNestedConversation();
       assert Manager.instance().isLongRunningConversation();
       Context conversationContext = Contexts.getConversationContext();
       assert conversationContext.get("conference") != null;
       setValue("#{customQuestionsDisplayListItemHome.instance.text}", text);
       }
      
       @Override
       protected void invokeApplication() throws Exception {
       invokeAction("#{customQuestionsDisplayListItemHome.persist}"); //ends nested conversation via navigation rule
       }
      
       }.run();
      
       cid = new NonFacesRequest(conferencePage, cid) {
       }.run(); //exception occurs here
      
      


        • 1. Re: StaleStateException from entity activation
          matt.drees

          Ok, I've reproduced this situation in a simple test:

          public class PassivatedEntityInParentConversationTest extends SeamTest {
          
           @Test
           public void test() throws Exception {
           String cid = new FacesRequest("/page.xhtml") {
           @Override
           protected void invokeApplication() throws Exception {
           Bar bar = new Bar();
           bar.setName("bar1");
           EntityManager entityManager = (EntityManager) getValue("#{entityManager}");
           entityManager.persist(bar);
           Contexts.getConversationContext().set("bar", bar );
           Manager.instance().beginConversation();
           }
           }.run();
          
           //bar is not passivated, because it was just added
          
           cid = new FacesRequest("/page.xhtml", cid) {
           }.run();
          
           //bar is now passivated
          
           cid = new FacesRequest("/page2.xhtml", cid) {
           @Override
           protected void invokeApplication() throws Exception {
           Manager.instance().beginNestedConversation();
           }
           }.run();
          
           cid = new FacesRequest("/page.xhtml", cid) {
           @Override
           protected void invokeApplication() throws Exception {
           Bar bar = (Bar) Contexts.getConversationContext().get("bar");
           bar.setName("bar2");
           EntityManager entityManager = (EntityManager) getValue("#{entityManager}");
           entityManager.flush();
           }
           }.run();
          
           //bar is not passivated, because it is not in the current conversation, so its wrapper still holds the old version
          
           cid = new FacesRequest("/page.xhtml", cid) {
           @Override
           protected void invokeApplication() throws Exception {
           Manager.instance().endConversation(false);
           }
           }.run();
          
           cid = new FacesRequest("/page.xhtml", cid) {
           }.run(); //exception occurs here at ConversationContext.unflush
           }
          }
          


          Exception:
          org.hibernate.StaleStateException: current database version number does not match passivated version number
           at org.jboss.seam.persistence.HibernatePersistenceProvider.checkVersion(HibernatePersistenceProvider.java:174)
           at org.jboss.seam.persistence.HibernatePersistenceProvider.checkVersion(HibernatePersistenceProvider.java:134)
           at org.jboss.seam.contexts.PassivatedEntity.checkVersion(PassivatedEntity.java:133)
           at org.jboss.seam.contexts.PassivatedEntity.getEntityFromEntityManager(PassivatedEntity.java:118)
           at org.jboss.seam.contexts.PassivatedEntity.toEntityReference(PassivatedEntity.java:73)
           at org.jboss.seam.contexts.EntityBean.activate(EntityBean.java:67)
           at org.jboss.seam.contexts.ServerConversationContext.unflush(ServerConversationContext.java:234)
           at org.jboss.seam.contexts.FacesLifecycle.resumeConversation(FacesLifecycle.java:129)
           at org.jboss.seam.jsf.SeamPhaseListener.afterRestoreView(SeamPhaseListener.java:373)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:211)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:184)
           at org.jboss.seam.mock.BaseSeamTest$Request.restoreViewPhase(BaseSeamTest.java:706)
           at org.jboss.seam.mock.BaseSeamTest$Request.emulateJsfLifecycle(BaseSeamTest.java:544)
           at org.jboss.seam.mock.BaseSeamTest$Request.run(BaseSeamTest.java:487)
           at org.uscm.crs.PassivatedEntityInParentConversationTest.test(PassivatedEntityInParentConversationTest.java:59)
           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.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:645)
           at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:479)
           at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:715)
           at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
           at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
           at org.testng.TestRunner.runWorkers(TestRunner.java:673)
           at org.testng.TestRunner.privateRun(TestRunner.java:620)
           at org.testng.TestRunner.run(TestRunner.java:480)
           at org.testng.SuiteRunner.runTest(SuiteRunner.java:278)
           at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:273)
           at org.testng.SuiteRunner.privateRun(SuiteRunner.java:253)
           at org.testng.SuiteRunner.run(SuiteRunner.java:168)
           at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:987)
           at org.testng.TestNG.runSuitesLocally(TestNG.java:951)
           at org.testng.TestNG.run(TestNG.java:719)
           at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
           at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)
          


          I created a jira issue.
          http://jira.jboss.com/jira/browse/JBSEAM-1656

          • 2. Re: StaleStateException from entity activation
            matt.drees

            Also, is it intended behavior that bar is not passivated at the end of the first request?

            • 3. Re: StaleStateException from entity activation

              After I upgraded to Seam 2.0, I also got the same error in my application about two weeks ago (http://www.jboss.com/index.html?module=bb&op=viewtopic&t=112769). I didn't have time to come up with a test case, so I'm glad that you also stumbled upon this problem.

              • 4. Re: StaleStateException from entity activation
                gavin.king

                I would really appreciate someone creating a runnable SeamTest-based test case and attaching to http://jira.jboss.com/jira/browse/JBSEAM-1656.

                This way I can actually merge the test into the Seam codebase.

                • 5. Re: StaleStateException from entity activation
                  matt.drees

                  Yeah, I can do that. Do you just want the SeamTest I posted above, or would you like more? What else would you want tested?

                  • 6. Re: StaleStateException from entity activation
                    matt.drees

                    Actually, would you mind briefly explaining what the requirements are for entity passivation? I'm not sure I conceptually understand what the goal is.

                    Specifically, when *should* a stale state exception be thrown?

                    • 7. Re: StaleStateException from entity activation
                      gavin.king

                      It should be thrown when some other user updated the entity in the database.

                      • 8. Re: StaleStateException from entity activation
                        matt.drees

                        Does the test I uploaded do what you'd like it to? I can work on it more it if not.