manager not closed at the end of the conversation!!!
deanhiller2000 Oct 10, 2008 11:10 PMI 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