简体   繁体   English

Hibernate禁用查询缓存

[英]Hibernate disable Query Cache

Following problem: 以下问题:

I create a Query to display all Entries of a MYSQL Table, if I edit a Field and execute the Query again I get the same (old) Result as in the first query. 我创建一个查询来显示MYSQL表的所有条目,如果我编辑一个字段并再次执行查询,我会得到与第一个查询相同的(旧)结果。

It seems that Hibernate caches the Result. 似乎Hibernate缓存了Result。 I tried to disable Caching with 我试图禁用缓存

query.setCachable(false) query.setCachable(假)

"hibernate.cache.use_second_level_cache" “hibernate.cache.use_second_level_cache”

"cache.provider_class" “cache.provider_class”

"org.hibernate.cacheable" “org.hibernate.cacheable”

flushing and closing the session 刷新和关闭会话

but nothing works 但没有任何作用

I think the configuration you want is 我认为你想要的配置是

hibernate.cache.use_query_cache = false

Reference . 参考

Could it be that you never saved or updated the the changed entry to hibernate? 可能是你从未保存或更新已更改的条目进入休眠状态? When the cache returns the wrong result that is usually an indication something else is wrong. 当缓存返回错误的结果时,通常表明其他错误。

it has nothing to do with 2nd or Query caches, these are already disabled by default! 它与2nd或Query缓存无关,默认情况下已禁用! What probably would help in your case is to call session.refresh(yourEntity) so that the state of your entity would be re-read by hibernate. 在您的情况下可能session.refresh(yourEntity)是调用session.refresh(yourEntity)以便hibernate重新读取您的实体的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM