Creating a post commit when using transaction in Spring
java, spring, transactions
Solution
You could get exactly what you want by a simpler way, with `TransactionSynchronizationManager` and `TransactionSynchronization`
With `TransactionSynchronizationManager`, you have static methods to get information about current transaction, and you can register a `TransactionSynchronization` wich allows you to automatically do a post-commit as you call that
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization(){
void afterCommit(){
//do what you want to do after commit
}
})
Be aware that the TransactionSynchronization is on a per-thread basis (which is often not a problem for a basic web request).
Problem
Due to certain reasons i have manually performed transaction commit and roll back using Spring PlatformTransactionManager, what i need to do is setup a hook so that a post commit action takes place after transaction has been committed. By looking at: ``` void commit(TransactionStatus status) throws TransactionException; ``` I cant see how i can determine a transaction was successful other than assumming it so if no expception are thrown. And i could use AOP as one option, but what about programmitcally doing it, maybe using callback method?