2 Replies Latest reply on Jul 18, 2008 4:12 PM by gjeudy

    getting a StaleObjectStateException

    deanhiller2000

      I have a table and a button that can change the state of things in the table(and the page will reload).  Basically, when you click close, the following method is called...



           public void closePosition(EmployerPosition pos) {
                pos.setState(EmployerPositionState.CLOSED);
                mgr.merge(pos);
           }



      Then right before re-rendering the page, the EmployerPosition list is reloaded via the following method BUT BUT it is loading the bean I just changed with the previous version number instead of the new version number!!!!!(I want it to use the after transaction number so I don't get StaleObjectExc)...the code....


      sorry about this but this forum gave me an error when pasting this next snippet of code for some dang reason.....
           
      "@DataModel
           private List<EmployerPosition> openPositions;
           @DataModel
           private List<EmployerPosition> otherPositions;
           
           @Factory("openPositions")
           public void fillInPositions() {
                
                Employer newEmployer = mgr.merge(employer);
                
                List<EmployerPosition> positions = newEmployer.getImmutableEmployerPositions();
                openPositions = new ArrayList<EmployerPosition>();
                otherPositions = new ArrayList<EmployerPosition>();
                
                for(EmployerPosition pos : positions) {
                     if(pos.getState() == EmployerPositionState.OPENED)
                          openPositions.add(pos);
                     else
                          otherPositions.add(pos);
                }
           }"


      Anyways, any idea how to get the transaction to commit BEFORE it starts the rendering phase of the next page so I can get the new position with it's version and everything and not get these StaleDataObjectExceptions????

        • 1. Re: getting a StaleObjectStateException
          deanhiller2000

          oh yeah, my closePosition is in an EVENT scoped bean and the list is in a SESSION scoped bean as I guess that state has to be in conversation, session or appliation so the event bean can be passed item X from the list to the method.....I wonder if therein lies the problem????  does the session bean keep that stuff cached and the versions are all still the old versions, but even then, the list would not be read after the transaction....how to make the list get read after the mgr.merge method call and the tx commit? so the list has the most recent versions of data?

          • 2. Re: getting a StaleObjectStateException
            gjeudy

            reformatted for readability:


            @DataModel 
            private List<EmployerPosition> openPositions; 
            
            @DataModel 
            private List<EmployerPosition> otherPositions; 
            
            @Factory("openPositions") 
            public void fillInPositions() { 
               Employer newEmployer = mgr.merge(employer); 
               List<EmployerPosition> positions = newEmployer.getImmutableEmployerPositions(); 
               openPositions = new ArrayList<EmployerPosition>();
               otherPositions = new ArrayList<EmployerPosition>();
               for(EmployerPosition pos : positions) { 
                  if(pos.getState() == EmployerPositionState.OPENED) 
                     openPositions.add(pos); 
                  else 
                     otherPositions.add(pos);
                }
            }



            The problem exposition is not clear, can you please provide more info such as your bean declarations, facelets snippets and stacktrace ?