When using @Transactional
in a service layer, is there any option to get a reference to the TransactionStatus
instance created by the PlatformTransactionManager
?
For instance, in the following code :
@Transactional
public void updateCustomer(...) {
// do some business stuff
// can we get here a reference to the TransactionStatus instance ?
}
TransactionStatus status = TransactionAspectSupport.currentTransactionStatus();
The currentTransactionStatus
method returns the transaction status of the current method invocation.
If you are interested in the result of a transaction, you could consider the TransactionSynchronizationAdapter
which provides a convenient afterCompletion(int status)
callback:
class AfterCompletionTransactionHandler
extends TransactionSynchronizationAdapter {
public @Override void afterCompletion(int status) { ... }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With