|
From: Andy D. <an...@ma...> - 2005-06-24 01:06:52
|
I've discovered that Spring's PlatformTransactionManager (JTA version in my case) will *always* invoke TransactionSynchronizations when its commit() method is called, even if it is participating in a pre-existing JTA transaction. Is this expected behavior? PlatformTransactionManager's JavaDoc for its "commit" method says, "If the transaction wasn't a new one, omit the commit for proper participation in the surrounding transaction." Which AbstractPlatformTransactionManager does indeed honor - however, it will still call any Spring TransactionSynchronizations against the transaction, as if a commit had been performed anyway. In my case, 3rd party code has started a JTA transaction (not using Spring) and then invoked my Spring based code. My Spring based code relies entirely on Spring for transaction management, and I use TransactionInterceptor around my business interfaces. TranactionInterceptor invokes PlatformTransactionManager, which joins in the already existing JTA transaction (things are going well so far). My code then registers a TransactionSynchronization, assuming that when "afterCompletion" is called on the synchronization that the transaction has been safely committed. However, once my business method exits, TransactionInterceptor will call commit() on PlatformTransactionManager which behaves well and does *not* tell JTA to commit since it had joined an already existing transaction. However, afterCompletion *is* called at this point on my TransactionSynchronization, causing my code to update an external resource as if the transaction is safely committed. However, the actual JTA transaction is still outstanding. What happens in my case is that sometimes the transaction will be rolled back by the 3rd party code, and not only is my TransactionSynchronization never notified, but it also already committed (now invalid) information to an external resource. Based on the description of TransactionSynchronization in Spring, it would seem like a safe assumption that the methods contained therein should track the actual transaction and not just Spring's participation in that transaction. Is this not true? - Andy |