-
Notifications
You must be signed in to change notification settings - Fork 35
Description
OK, while trying to understand the situation with #223, it hit me that somewhere along the way we appear to have lost the capability we used to have with @javax.ejb.ApplicationException
, that is, the ability to mark an exception type as causing or not causing the transaction to be set to rollback-only in a global way, instead of having to remember to list it in the @Transactional
annotation of every bean which throws it. It's a sort of trivial thing that can help reduce mistakes.
We should have that capability somewhere, and since @Transactional
is defined here, it makes most sense to put it here.
People barely use checked exceptions anymore, so I think we can safely assume that it's always going to be applied to an unchecked exception type, with the purpose of suppressing the default behavior which is to mark the tx for rollback. (The legacy ApplicationException
could also be applied to checked exception types.)
That is to say, this is an annotation you would use to indicate that an unchecked exception is one that you intend t o handle in application program logic, and recover from. I can't really think of any sensible use-case for the inverse of this where you would mark a checked exception as unrecoverable.
So, how about just calling this @Recoverable
, declaring it @Inherited
, with no members. Something like this:
/**
* Marks an unchecked exception type is recoverable,
* so that it does not result in the transaction being
* {@linkplain Transaction#setRollbackOnly marked for
* rollback} when thrown by a {@link Transactional}
* managed bean.
* <p>
* The annotated exception type must be a subclass of
* {@link RuntimeException}.
* <p>
* The effect of this annotation may be suppressed for
* a given managed bean by explicitly listing the
* exception type in {@link Transactional#rollbackOn}.
*
* @since JTA 2.1
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Recoverable {}