如何在Quarkus中将事务设置为读操作必须的?

huangapple go评论56阅读模式
英文:

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.

英文:

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.

答案1

得分: 1

可以在事务外部访问一个只读的实体管理器/会话。在我看来,这是非常值得怀疑的行为,但实际上有些人确实依赖于这一点。

据我所知,没有内置的方法来禁用这个,但你可以提出一个配置属性的建议在此处提出一个问题

英文:

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.

huangapple
  • 本文由 发表于 2023年6月13日 16:04:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/76462858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定