I have a REST webservice that manage its transactions using the following approach:
@Inherited
@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({METHOD, TYPE, FIELD, PARAMETER})
public @interface TransactionRequired {
}
@Interceptor
@TransactionRequired
public class TransactionRequiredInterceptor {
@Inject
private EntityManager entityManager;
@AroundInvoke
public Object manageTransaction(InvocationContext ctx) {
try {
..start transaction..
}
catch(Exception e) {
..rollback..
}
}
}
And I am also mapping my exceptions like this:
@Provider
public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
@Override
public Response toResponse(RuntimeException exception) {
.. return some response..
}
}
The issue is that when, lets say, an RuntimeException is thrown (after transaction being started), it is immediatelly intercepted by the RuntimeExceptionMapper and the transaction is never rollbacked.
Being so, I need a way to priorize the TransactionRequiredInterceptor..
Obs: Using @Transactional is not an option since I need to deploy on Tomcat 8.