I have a RESTFul service (implemented by jersey) . The service is marked with @Transactional.
I declared an ExceptionMapper like this:
@Provider
public class ThrowableMapper implements ExceptionMapper<Throwable> {
private static final Logger log = Logger.getLogger(ThrowableMapper.class);
public Response toResponse(Throwable ex) {
log.error("throwable", ex);
return Response.status(500).entity("Internal Error").type("text/plain").build();
}
}
when exceptionmapper is not declared than transaction is rollback. However, when i have an ExceptionMapper transaction is commit without rollback.
I assume the reason for for transaction not being rollback is because when exception is caught by ExceptionMapper than spring transaction proxy dosnt detect that exception was thrown ,so transaction is not rollback.
Is there a way to overcome this?