Yes. Sorry. I got side tracked working on something else. Code is forthcoming.Quote:
Originally Posted by curtney
Here's a few of the challenges to implementing long hibernate sessions using a FlowExecutionListener. Please weigh in if you're so inclined.
1) As of this moment, my OpenSessionInFlowListener applies to all flows without exception. There doesn't seem to be a convenient way to disqualify a listener from hearing about an execution of a certain flow. It might be nice to be able to 'turn off' this listener for certain flows. This deficiency exacerbates the problem realized by having a hibernate session stored in flow scope: a potentially large memory footprint per flow.
2) Objects returned by hibernate queries become increasingly stale over the life of the flow.
3) Hibernate sessions are started even for flows that don't access hibernate. This is also the case with the OpenSessionInView strategy.
4) I don't think the OpenSessionInView strategy will play nice with the OpenSessionInFlowListener. OpenSessionInView tries to close the hibernate session when the request is finished. This spoils the point of the long hibernate sessions and will likely cause an exception.
Issue #1 can be mitigated by use of the ExpiredFlowCleanupFilter which will remove expired flows and their associated hibernate sessions. I'm also tinkering with the idea of a FlowExecutionManager that enforces certain flows as singletons per http session. This will also help keep the memory footprint in check.
Issue #2 might or might not be a problem for your application. Either way, the current implementation allows you to optionally clear the hibernate session every time the flow session becomes active. This is configured on a per-flow basis and is arguably not the most flexible solution.
Issue #3 is not a problem that deserves any real attention. Does anyone disagree?
Issue #4 is sort of a stumper. I have a feeling that there might be a way to extend the OpenSessionInView components in such a way that they don't step on the OpenSessionInFlowListener's work. Any ideas here are of course welcome.