6 Replies Latest reply on Oct 12, 2008 8:33 PM by Dean Hiller

    manager not closed at the end of the conversation!!!

    Dean Hiller Expert

      I have a script which had 3 nodes and one of those nodes has a Map of paths(answer property of path is the key).  When I end the conversation with @End, I notice the manager is not closed and when the next page is displayed, a query is run to get all the scripts. 


      Code....


              //This is run right after I click save to save the script
          @End
          public void save() {
              mgr.flush();
          }
      
          //This method is in a different class and runs right
          //after save and the SAME mgr instance is injected here
          public void fillInScripts() {
               scripts = ScriptModel.getAllScriptModels(mgr);
          }



      So far it is okay, but now that query returns all the scripts from the database and one of those scripts IS THE script we just saved which already has it's nodes and their paths attached.  This is okay(but I would like it to be a clean copy so I could fix the problem I am about to illustrate).
      NOTE: The mgr used to run the query is the one from the previous conversation if you are debugging in eclipse, you can see it is the same instance and the mgr has not been closed yet.  This is why mgr.getAllScriptModels returns the cached script....if this was not the case, my bug would go away :(...moving on to illustrate the bug....


      So then, a user chooses a script from the list.  when he does this a new method like so is called...


           @Begin(flushMode=FlushModeType.MANUAL)
           public void editScript(ScriptModel s) {
                this.script = mgr.merge(s);
                node = script.getRootNode();
              }



      Now the weird part.  mgr.merge(s) returns a script object model that IS DIFFERENT than the one passed in to mgr.merge method.  The one passed in has a script with 3 nodes and node with name zzzzz has 2 paths(one with yes and one with no) in the Map<String, Node> of the node class.  The script returned from mgr.merge ONLY HAS ONE Path object.  I look in the database and the database has TWO!!!  but the merged script's node only HAS ONE.


      Then I click somewhere else and then load hit the page that lists the scripts yet again.  This time it loads a clean script object without the nodes.  In this case it works fine as I go from page to page and it loads the nodes then the decision paths.  IT ONLY BREAKS WHEN THE mgr from the previous conversation is used to load the next page even though the conversation was supposed to end on the Save method call and before the query method was called(or maybe not supposed to be but I would like it too so I could work around this bug...I think it might be a hibernate bug but am not sure).


      Anyone?  I doubt I will get a response but I thought I would try :).



      More detail...


      ScriptModel.java has a List<Node> children;
      Node.java has a Map<String, Path> paths;




      In the DB, Node zzzz has two paths from it and after mgr.merge, it only has one IF the mgr was from the previous conversation.  If the mgr is a new mgr, then it just returns a script with Nodes not initialized yet.  then the next page causes the Nodes to get initialized and the next one causes TWO paths to be loaded correctly....Only when using the mgr from the PREVIOUS conversation does the bug exist.


      MAN, what a mouthful.....not even sure I explained this clearly enough...let me know.


      Dean



        • 1. Re: manager not closed at the end of the conversation!!!
          Dean Hiller Expert

          duh....I now work around it by navigating to a success page :(.  That will have to work for now but boy would I love to navigate back to the list.  It just breaks when I navigate back to the list, but works fine if I go to the success page first.  not sure if that is a seam or hibernate bug.

          • 2. Re: manager not closed at the end of the conversation!!!
            Francisco Jose Peredo Noguez Master

            I coulnd't get what was the problem... could you please try to re-state it a more...mmm... algorithmic way? something like, step 1, step 2, step 3, and explain then in what step something should have happened in a different way?

            • 3. Re: manager not closed at the end of the conversation!!!
              Dean Hiller Expert

              Sure, no problem. 


              Step 1. Display the page with the list
                 Substep A. This results in a query being run that just gets all the scripts
              Step 2. Click Edit on a script
                 Substep A. This results in the following method being called


                   @Begin(flushMode=FlushModeType.MANUAL)
                   public void editScript(ScriptModel s) {
                        this.script = mgr.merge(s);
                        node = script.getRootNode();
                      }



                 Substep B. the page is displayed which includes calling
                             node.getPathMap().get(yes);
                             node.getPathMap().get(no);
                             Both of those return Path objects correctly at this point
                 Substep C. Page is displayed after the rest of the get methods with a save and finish button
              Step 3. Click Save and Finish
                  Substep A. This results in this method being called


                   @End
                   public void save() {
                        mgr.flush();
                   }


              Let's say the id for this manager in eclipse is 618 here


                  Substep B. Seam figures out the next page and starts wiring it together which results in this method being called


                   public void fillInScripts() {
                        Query query = mgr.createNamedQuery("getAllScriptModels");
                        scripts = query.getResultList();
                  }



              NOTE: This mgr is also id=618.  It is the same manager used during the conversation as the conversation probably does not end until the response page is sent back to the browser(I am guessing).


              MOVING ON....
              Step 4. You now click edit the SAME script again(here is where things go haywire). 
                    Substep A. This results in the same method being called above BUT now with bad results...



                   @Begin(flushMode=FlushModeType.MANUAL)
                   public void editScript(ScriptModel s) {
                        this.script = mgr.merge(s);
                        node = script.getRootNode();
                      }



                 Substep B. the page is displayed which includes calling
                             node.getPathMap().get(yes);
                             node.getPathMap().get(no);
                             NOW, node.getPathMap().get(yes) returns null
                                  node.getPathMap().get(no) returns the correct path.


              NOTE: If between STEPS 3 and 4, I instead REFRESH the browser page, and then I click edit, it works fine!!!! 


              SECOND NOTE: The s variable above passed into editScript actually contains a correct object model where the following methods return the correct results....
                             node.getPathMap().get(yes);
                             node.getPathMap().get(no);


              AFTER the script is merged, the first method returns null and the second returns the correct results.  I have no idea why this happens.


              Dean

              • 4. Re: manager not closed at the end of the conversation!!!
                Dean Hiller Expert

                damn formatting....enter should mean enter!! ahhh.  This is a pain.  It should be more WYSIWYG on formatting.  Oh well, this is the best I could do to straighten it out....


                let me try again...


                Sure, no problem.


                Step 1. Display the page with the list
                   
                Substep A. This results in a query being run that just gets all the scripts


                Step 2. Click Edit on a script
                   
                   Substep A. This results in the following method being called



                     @Begin(flushMode=FlushModeType.MANUAL)
                     public void editScript(ScriptModel s) {
                          this.script = mgr.merge(s);
                          node = script.getRootNode();
                        }




                Substep B. the page is displayed which includes calling



                node.getPathMap().get(yes); 
                node.getPathMap().get(no); 




                Both of those return Path objects correctly at this point


                Substep C. Page is displayed after the rest of the get methods with a save and finish button


                Step 3. Click Save and Finish


                Substep A. This results in this method being called



                     @End
                     public void save() {
                          mgr.flush();
                     }




                Let's say the id for this manager in eclipse is 618 here


                Substep B. Seam figures out the next page and starts wiring it together which results in this method being called



                     public void fillInScripts() {
                          Query query = mgr.createNamedQuery("getAllScriptModels");
                          scripts = query.getResultList();
                    }




                NOTE: This mgr is also id=618. It is the same manager used during the conversation as the conversation probably does not end until the response page is sent back to the browser(I am guessing).


                MOVING ON.... Step 4. You now click edit the SAME script again(here is where things go haywire). Substep A. This results in the same method being called above BUT now with bad results...



                     @Begin(flushMode=FlushModeType.MANUAL)
                     public void editScript(ScriptModel s) {
                          this.script = mgr.merge(s);
                          node = script.getRootNode();
                        }




                Substep B. the page is displayed which includes calling



                node.getPathMap().get(yes); 
                node.getPathMap().get(no); 




                NOW, node.getPathMap().get(yes) returns null node.getPathMap().get(no) returns the correct path.


                NOTE: If between STEPS 3 and 4, I instead REFRESH the browser page, and then I click edit, it works fine!!!!


                SECOND NOTE: The s variable above passed into editScript actually contains a correct object model where the following methods return the correct results.... node.getPathMap().get(yes); node.getPathMap().get(no);


                AFTER the script is merged, the first method returns null and the second returns the correct results. I have no idea why this happens.


                Dean

                • 5. Re: manager not closed at the end of the conversation!!!
                  Dean Hiller Expert

                  one more not.  The correct results are that both of these methods return non-null results which happens every single time just fine unless I click save and finish and immediately edit the same script(edit any other script, or refresh the list first or do anything to cause the mgr to NOT be the one in the conversation and all works great).


                  node.getPath().get("yes");
                  node.getPaht().get("no");



                  first one returns null in the failure case.



                  • 6. Re: manager not closed at the end of the conversation!!!
                    Dean Hiller Expert

                    YEAH!!!!!!  I figured it out.  All I needed was to add this



                    @End(beforeRedirect=true)




                    and now the mgr used in the query is brand new so it gets around the mgr.merge bug(well, at least, I think that is a bug since the merge resulsts are different than the database AND different than the object model I passed in.....and that object model I passed in matches the database too....go figure).  Anyways, it works around the hibernate but....I am sooooo happy now.


                    Hope that helps someone else.