global Exception Handler overrules database transaction handler

  Kiến thức lập trình

Iam sort of stuck at a particular funny error in a quarkus REST-service that Iam currently developing.
My appplication manages panache entities and I implemented some CRUD operations in a resource controller.
I annotated that controller with @Transactional(like the documentation suggest) and for good measure I added a global exception handler which looks roughly like the following snippet:

import jakarta.ws.rs.core.Response;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;


public class MyExceptionHandler {
    @ServerExceptionMapper
    public Response entityToBig(EntityToBigException e) {
        return Response.status(Response.Status.BAD_REQUEST)
    // ErrorMessage is just a record to hold the message
    .entity(new ErrorMessage("Error", e.getMessage(), Response.Status.BAD_REQUEST.getStatusCode())).build();
    }

   //... other handlers
}

The thing is now, that if I throw a Exception which is handled by my ExceptionHandler class the Status code and message is preseted corectly to the enduser but the changes done in the prior request are ALSO commited to the database!

If I throw a Exception that is not handled by my ExceptionHandler class the transaction rollback works just fine…

I could not find any other documentation on this issue so Iam quite perplexed on how to solve this/manuly tell the transaction manager to rollback my changes.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT