This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Compound Transactions

Feb 28th, 2007, 06:11 PM

Hello,

My question relates to programmatic transactions. I am using the TransactionTemplate to execute TransactionCallback implementations.

I have two of these TransactionCallback implementations in seperate packages. One of these makes a call to the DAO object, writing or deleting an object and also performing another task with that object, all wrapped in a doIntransaction() method.

The other TransactionCallback implementation makes a call to another DAO. I want to make the second TransactionCallback implementation make a call to the first TransactionCallback implementation. My question is if I make that call from within the second TransactionCallback implementation doIntransaction() method and an exception and roll back occurs in the first TransactionCallback implementation, will the calling second TransactionCallback implementation automatically roll back or do I have to trow the exception again in the first TransactionCallback ?

If I understand you correctly, you have TransactionTemplate that ends up calling into another tranasction template. If a RuntimeException gets thown within the second one, they will both be rolled back. The TransactionTemplate basically rolls back and then re-throws the exception. If in doubt you can always have a look at the source code.