New EntityManager sometimes getting stale data from MySQL

送分小仙女□ 提交于 2019-12-06 06:16:47

For some reason I thought the implicit transaction entityManager joins was a new transaction. But Hibernate docs state: "When you create an entity manager inside a transaction, the entity manager automatically join the current transaction."

So apparently there is another transaction already running (not surprising) and my fetch results change depending on what it had already read (because the database is running in REPEATABLE-READ mode.)

In the short term I will sweep through my code to explicitly begin() transactions wherever that's missing. Longer term, I will look into Spring Transactions to see about managing transactions in a more foolproof manner (as was suggested in the comments.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!