How to disable hibernate caching

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

    You can use:

    session.setCacheMode(CacheMode.IGNORE)

    after your:

    session.createQuery("from Table") statement.

    This will ensure that Hibernate doesn't interact with 2nd level cache for any entity returned by this query.

提交回复
热议问题