Problem with rollback during commit

Hi,

as mentioned in the reference manual I have configured my command-bus with a transaction-manager (Spring) - <axon:command-bus id=“commandBus” transaction-manager=“transactionManager”/>.

Now when during the commit an exception arises - e.g. a ConstraintViolationException - Spring catches that exception and performs a rollback. Then the exception is thrown again and catched by Axon which also triggers a rollback and tells the transaction-manager to rollback. That leads to a IllegalTransactionStateException because the transaction is already marked as completed because of the first rollback.

First rollback is triggered in org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit() via doRollbackOnCommitException().
Second rollback is triggered in org.axonframework.unitofwork.NestableUnitOfWork.commit() calling org.axonframework.unitofwork.DefaultUnitOfWork.doRollback() which calls transactionManager.rollbackTransaction() resulting in AbstractPlatformTransactionManager.rollback() which throws the mentioned IllegalTransactionStateException.

Do I do anything wrong or is this a bug?

Regards
Felix

Hi Felix,

it looks like a combination of both. Axon does a rollback when a commit fails. Unfortunately, this also involves a rollback of a transaction. The TransactionManager has a setting that allows you to indicate whether it should do a rollback on a commit failure. The default is ‘false’, according to the documentation.

The ‘bug’ part is where Axon fails to check whether it makes sense to attempt a rollback. So while I’m working to fix this, you can use the setRollbackOnFailedCommit (or a similar wording) to disable this setting.

Cheers,

Allard