see AbstractPlatformTransactionManager:782
Errors on afterCommit still trigger afterCompletion with committed status.
This confuses our custom synchronization callback, into performing its "afterCompletion" action even though the "afterCommit" step of the transaction has failed. This is present in the latest code and our only option is to track the flow of the transaction in our custom synchronization callback to confirm that "afterCommit" has been called before "beforeCompletion"
We believe this is a bug and should be handled more explicitly, probably with an additional synchronization callback method and/or an adjustment to the transaction flow.
More precisely, org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerSynchronization.afterCommit
synchronization callback is throwing an error which is not captured by AbstractPlatformTransactionManager
Comment From: eliasbalasis
On second thought, the call to "afterCompletion" carries a "statusCode" which is STATUS_ROLLED_BACK or STATUS_UNKNOWN if the transaction flow has been interrupted by unexpected error during "commit" and we should be using this to control our flow.
Also, if an unexpected error occurs during "afterCommit" we are handling it accordingly.
There is no need for additional synchronization callback method and/or adjustment to the transaction flow.