Search code examples
transactionsquarkusquarkus-panache

How can I set transactions mandatory for read operations in Quarkus?


I recently discovered that I can perform read operations using a Panache repository during a QuarkusTest without an active transaction. This behavior took me by surprise, and it also resulted in incorrect data being returned (possibly due to caching). As soon as I put an active transaction around the test, everything works as expected. Unfortunately, I couldn't reproduce the issue with a reproducer. I attempted to find a configuration option to enforce a transaction for read operations, but I was unable to locate a suitable setting.

How can I configure Quarkus with Hibernate ORM to make transactions mandatory, even for read operations?

It seems that setting the TransactionRequirement to STRICT is not a viable solution for me, as it would prevent the Liquibase migration from executing.


Solution

  • Yes, you can access a read-only entity manager / session outside of transactions. That's (very) questionable behavior in my opinion, but some people actually rely on that.

    There is no built-in way to disable that as far as I know, but you can certainly open an issue to suggest a configuration property.