How to disable hibernate caching

后端 未结 7 1094
梦谈多话
梦谈多话 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 04:04

    Can someone please answer how to disable caching in persistence.xml.

    The second-level cache and query cache are disabled by default (and queries are not cached unless you explicitly cache them). The first-level cache can't be disabled.

    I tried to disable by changing properties (...)

    This would disable the second-level cache and query cache, if they were enabled.

    But It did not work.

    To be honest, "it did not work" is a very poor description of the current behavior vs the expected one. Providing more details, (pseudo) code, SQL traces would probably help.

    That being said, if the question is about HQL, an HQL query should definitely hit the database upon subsequent execution (without any query cache). Activate SQL logging if required to observe this.

    If the question is about Session#get() or Session#load(), then you could reload the state of an entity using Session#refresh() or call Session#clear() to completely clear the session.

    0 讨论(0)
提交回复
热议问题