How to disable hibernate caching

后端 未结 7 1129
梦谈多话
梦谈多话 2020-11-30 03:04

I am trying to write a unit test class which will have to use same query to fetch the results from database two times in same test method. But as Hibernate cache is enabled

7条回答
  •  自闭症患者
    2020-11-30 03:40

    According to a guy from the hibenrate team :

    The second-level cache has nothing to do with the first-level (session or persistence context) cache. The persistence context/session cache is mandatory for various reasons. In fact, not understanding this crucial part and ignoring it in application architecture is a recipe for disaster. There is no quick solution here, study some documentation.

    Source :https://forum.hibernate.org/viewtopic.php?p=2383408
    You might use seesion.evict(your object) before retrying the same query.

提交回复
热议问题