Long Transactions
jesse_sweetland Mar 16, 2006 8:32 AMjBPM version: 3.1
App server: JBoss 4.0.3
I was looking at the Hibernate mapping files and none of the associations that I looked at include "lock" in the cascade. So, for example, if I call Session.lock on a TaskInstance, only that TaskInstance is reassociated with the Hibernate session. If that TaskInstance has associations that are initialized under another Hibernate session (using the session-per-request-with-detached-objects pattern) then they are not reassociated with the new session unless I explicitly lock each associated object.
The problem I am having is that in one request (session1) I traverse the graph back up to the root token to construct a "canonical name" for a token (process/state/sub-process/super-state/state/task). This initializes the token's parent tokens, the tokens' respective nodes and process instances, the process instances' process definitions and super-tokens, and so forth on up to the root token. Then, in another request (session2), I signal the token, which apparently traverses the tree back up to the root trying to load events at each node. The problem is that all of those objects were loaded in and are still associated with session1, which is now closed, resulting in a LazyInitializationException. To fix this, I have two options:
1. Call session.refresh() instead of Session.lock() on the token I want to signal and start over
2. Traverse the tree all the way back up to the root and lock each object
The first solution seems reasonable, except for the note in the Hibernate 3.1 JavaDoc indicating that it is inadvisable to use the Session.refresh method to implement long transactions. I suspect this is because one might unintentionally lose changes in associated objects since they are discarded, or perhaps the concern has more to do with performance (issuing all of those queries again). The second solution is just a messy hack that could instead be accomplished automatically in Hibernate with a cascading lock operation on all of the associations.
It is understandable that the associations do not cascade lock operations, especially since it's dealing with hierarchical/recursive data (as there is a possibility of NonUniqueObjectExceptions). But has any thought gone into long transactions and how best to handle them in jBPM? What is the preferred method?
Thanks,
- Jesse