I have a DAO class catching the javax.persistence.PersistenceException
wrapping them and rethrowing it as a checked exception. This method is marked as @org.springframework.transaction.annotation.Transactional
.
If I get an exception in my DAO like constraint violation it will be wrapped in my custom Exception, however spring overrides my exception
[tp1415357209-22] o.s.t.i.TransactionInterceptor : Application exception overridden by commit exception
and throws it's own org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
"swallowing" my exception by just logging it and rethrowing its own exception. How can I prevent spring from doing this?
P.S.
@Transactional(noRollbackFor = { MyCustomException.class})
does not work. Of course I do want the transaction to set as rollback but I don't want my exception being swallowed by spring.
The solution was to use rollbackFor
instead of the other attribute so that spring doesn't swallow my own exception
In case you have a few different Checked Exceptions that you can raise in your class or method, you can use the generic Exception class as well
@Transactional(rollbackFor = Exception.class)
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