grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.78k stars 950 forks source link

GRAILS-5529: Attached instances are momentarily detached when back from subflow #3145

Closed graemerocher closed 9 years ago

graemerocher commented 14 years ago

Original Reporter: benje Environment: Not Specified Version: 1.1.1 Migrated From: http://jira.grails.org/browse/GRAILS-5529

In [SessionAwareHibernateFlowExecutionListener, line 65|http://github.com/grails/grails/blob/master/grails/src/java/org/codehaus/groovy/grails/webflow/persistence/SessionAwareHibernateFlowExecutionListener.java#L65], the {{sessionEnded()}} method should not generate a {{paused()}} event on ending subflows.

Indeed, this {{paused()}} event actually unbinds the Hibernate session from the tx sync manager. Then in the main flow (especially in transitions criteria closures of the subflow state, and in subsequent actions states), formerly attached instances are seen as detached because the session is no more bound in the tx sync manager.

After the session got bound again (with a {{resume()}} event, i.e. one view sate later in the flow life time), the attached instances are properly seen as attached again.

Attached is a complete Author-Book Grails app to demonstrate the problem, with real world flow and subflow (inspired by professional app), and a test case that shows the problem can't be identified in an integration test. You actually have to run the app to see the issue.

To fix the issue in the demo app, you just need to edit the custom {{LoggingSessionAwareHibernateFlowExecutionListener}} class and set the {{doNotGeneratePausedEvent}} boolean to {{true}} in the {{sessionEnded()}} method body.

graemerocher commented 14 years ago

benje said: This might be related indeed. I'll try some further tests to demonstrate it.

graemerocher commented 14 years ago

ovaris said: Actually what was causing Session closed exception was that my sublow form action pointed to parent flow action. But there's another problem, flow does not return to main (or parent) flow from subflow, I created new issue: GRAILS-5552

graemerocher commented 14 years ago

benje said: Okay you answered before I did, but we finally reached the same conclusion. ;-)

graemerocher commented 14 years ago

graemerocher said: fixed by commit http://github.com/grails/grails/commit/cf3785d6905e08791daedee6cc83b4ab15813894

graemerocher commented 14 years ago

ovaris said: Okay, my problem was caused because of incorrect use of g:form action parameter. I did have g:form action="toParent" in my sublow view page, but this is not a real problem since on a subflow page I should point my form action to subflow "action"....There was another issue open regarding returning back from subflow to mainflow, which is resovled already, GRAILS-5552.