Environment: Java 8, JEE 7 (no Spring), JBoss 7 GA, EJBs and ManagedBeans, Informix and Oracle DB, using default CMT.
I found the following statement regarding unchecked exception and its rollback behavior:
"[...] unchecked Exceptions (RuntimeExceptions) will usually cause a rollback of a transaction (unless annotated as @AppliationException(rollback=false)"
So now the javadoc of the following unchecked exceptions
javax.persistence.NonUniqueResultException.classjavax.persistence.NoResultException.class
state:
"This exception will not cause the current transaction, if one is active, to be marked for rollback."
Weirdly the NonUniqueResultException did cause my transaction to be rolled back. So I added the following lines to the method:
@javax.transaction.Transactional(dontRollbackOn = {javax.persistence.NonUniqueResultException.class,
javax.persistence.NoResultException.class})
Additionally I wrapped these exceptions with my custom unchecked exception (... MyOwnException extends RuntimeException) but I am uncertain of the default behavior:
Three questions:
(1) When my own custom exception is thrown, does it rollback the current transaction or not? (It is not annoted with @AppliationException) (2) What is the JEE spec compliant behavior (since obviously the real world JEE implementation differ)? (3) And in the case the transaction would be marked for rollback and I have quite a call hierarchy do I have to add dontRollbackOn at each method or only once per transaction?