I am using Hibernate Reactive with Panache. I have the following event handler:
@ConsumeEvent(value = "save-result")
@ReactiveTransactional
public Uni<ResultEntity> saveResult(ResultMessage msg) {
ResultEntity result= msg.getResultEntity();
result.setComplete(true);
LOGGER.log(Level.INFO, "======> About to save Result: {0}", result);
return resultRepository.persistAndFlush(result)
.onItem().invoke(() -> LOGGER.log(Level.INFO,
"Result has been saved");
}
The event is being consumed (the log "About to save..." is printed), but the entity is not being saved. It is as if the transaction is not being subscribed to. (the log message "Result has been saved" is not being printed either)
I'm running on Quarkus 2.16.7 (prior to that, I tried with 2.12.x with no luck).
Note that I have another ApplicationScoped bean where a similar operation (though more complex) works just fine.
I'm not new to Quarkus (I've been working with it for a couple of months), but I'm not an expert either, and yet I am dumbfounded that this does not work.
Why is the transaction not being executed? Am I missing something?
UPDATE: For testing purposes, I have changed the code a bit, by adding another log line as seen below, to check whether the Uni is being subscribed and apparently it is (since "----> in flow" is being outputted), yet the entity is not persisted and "Result has been saved" is never printed either.
@ConsumeEvent(value = "save-result")
@ReactiveTransactional
public Uni<ResultEntity> saveResult(ResultMessage msg) {
ResultEntity result= msg.getResultEntity();
result.setComplete(true);
LOGGER.log(Level.INFO, "======> About to save Result: {0}", result);
return Uni.createFrom().voidItem().onItem()
.invoke(() -> LOGGER.log(Level.INFO,"----> in flow"))
.onItem().transformToUni(unused -> resultRepository.persistAndFlush(result)
.onItem().invoke(() -> LOGGER.log(Level.INFO,
"Result has been saved")));
}
I suspect that it might be an issue similar to https://github.com/quarkusio/quarkus/issues/12925 or to https://github.com/quarkusio/quarkus/issues/14591 but I cannot confirm that.
So I added .onFailure().invoke(Throwable::printStackTrace)
right after persistAndFlush
and saw that the operation threw a HibernateException.
This means that the exceptions are silently captured and ignored when executed within a @ConsumeEvent
method, and therefore the transaction never completes. (similar to the closed issues described here and here).
Seems like another issue needs to be opened for this.