I'm trying to use the quarkus-hibernate-reactive
extension with the quarkus-vertx
extension and I have issues persisting data. My project looks roughly like this:
FruitResource:
@Inject
EventBus eventBus;
@POST
public Uni<Response> create(Fruit fruit) {
if (fruit == null || fruit.getId() != null) {
throw new WebApplicationException("Id was invalidly set on request.", 422);
}
return eventBus.<Void>request("create-fruit", fruit)
.map(ignore -> Response.ok(fruit).status(201).build());
}
FruitService:
@Inject
FruitRepository fruitRepository;
@ConsumeEvent("create-fruit")
public Uni<Void> createFruit(final Fruit fruit) {
return fruitRepository.create(fruit);
}
FruitRepository:
@Inject
Mutiny.Session mutinySession;
public Uni<Void> create(final Fruit fruit) {
return mutinySession
.persist(fruit)
.chain(mutinySession::flush);
}
The exception I get is a java.lang.IllegalStateException: Session/EntityManager is closed
, which I assume happens during the flush()
. I guess my session closes somewhere down the way but I have no idea where and how to prevent this.
The full example can be found here: https://github.com/bamling/quarkus-hibernate-reactive-test
FruitsEndpointTest
simulates the behaviour!