PDA

View Full Version : Where should one implement hibernate transaction management in a flow.


garpinc2
Apr 4th, 2006, 12:34 PM
Where should one implement hibernate transaction management in a flow?

I would like to use FlowExecutor as a state machine where the actions may execute hibernate transactions. Transactions may span accross multiple actions so where is the best place to introduce hibernate transaction manager?

Keith Donald
Apr 4th, 2006, 01:28 PM
One idea is to attach a FlowExecutionListener that starts a transaction on stateEntering for ActionState's marked with a "transactional" attribute, then commits on "stateEntered" -- assuming your actions are all invoked within a chain as part of one state.

The issue is if one of your action methods throws an exception... how are you going to handle that so you can properly rollback. So it might be better to use a TransactionalActionChain composite action that does this for you, so you can catch exceptions and do a rollback.

Keith

garpinc2
Apr 4th, 2006, 01:49 PM
Can you do that in the flow xml file? If so how? Same also for AnnotatedAction? How do I specify that type of action. I don't see that it is supported in dtd. In fact I don't even see class TransactionalActionChain in javadoc.

Keith Donald
Apr 4th, 2006, 10:20 PM
Well, you would need to implement it; there is no such class in the framework at this time, I was only making a suggestion.

Simply by using the "bean" attribute of the action element you can reference any Action implementation in the flow builder context or any parent context. So one idea is to reference a TransactionalCompositeAction bean that is similiar to CompositeAction that applies the transaction demaraction to a collection of ordered actions.

Keith