I'm stuggling with auto-rollback of a container managed transaction. I understand that when throwing an exception, this should happen automatically, but somehow, this isn't happening.
To be clear, I have a JAX-RS ContainerResponseFilter
which throws some kind of RuntimeException (I can't throw a checked exception btw, as that would mean I need to specify "throws", which can't be done on an implementing method).
When I call sessionContext.setRollbackOnly()
myself, the transaction is rolled back indeed, but I don't really want to handle it myself.
I tried marking the exception as @ApplicationException(rollback=true)
but that doesn't make a difference.
Any ideas? This is on JBOSS 7.2 with RestEasy.
I've been unable to confirm this is intended behaviour, but any manual rollback within the ContainerReponseFilter
is just too late, as the transaction was committed already.
To resolve the problem, I've reworked my solution to throw the exception from within an Ìntegercepter
with @AroundInvoke
. This appears to be in time for the auto-rollback, and allows me to avoid throwing further exceptions in the ContainerResponseFilter