如何完全禁用Hibernate缓存? (在Spring 3中,带有注释的Hibernate) [英] How to disable completely Hibernate caching? (with Spring 3, Hibernate with annotations)

查看:162
本文介绍了如何完全禁用Hibernate缓存? (在Spring 3中,带有注释的Hibernate)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我的Java应用程序每10秒向mysql服务器询问一次查询.
我手动将新行插入表中.
而且Hibernate找不到它.
同样,当我手动删除一行时,Hibernate显示该行存在.
我建议这是因为Hibernate缓存.
有什么办法可以禁用它吗?
谢谢!


My java app asks mysql server for a query every 10 seconds.
I manually insert into table a new row.
And Hibernate can't find it.
Also when I manually remove a row, Hibernate shows that this row exists.
I suggest that it is because Hibernate caching.
Is there any way to disable it at all?
Thank you!

推荐答案

您是指一级缓存还是二级缓存?具有 Hibernate 二级缓存,例如 Ehcache 缓存与您手动修改的同一表中的行相对应的实体时,可能会导致您描述的行为.一级缓存不会导致这种行为,而且我认为您也无法禁用它.

Do you mean the first-level cache or the second-level cache? Having a Hibernate second-level cache such as Ehcache that caches entities that correspond to the rows in the same table that you modify manually could cause the behaviour that you describe. The first-level cache would not cause this behaviour, and I don't think you can disable it, anyway.

要禁用Hibernate二级缓存,请从Hibernate配置文件hibernate-cfg.xml中删除所有引用二级缓存的行.例如:

To disable the Hibernate second-level cache, remove from the Hibernate configuration file, hibernate-cfg.xml, all lines that refer to the second-level cache. For example:

<!-- Enable the second-level cache  -->
<property name="hibernate.cache.provider_class">
    net.sf.ehcache.hibernate.EhCacheProvider
</property>
<property name="hibernate.cache.region.factory_class">
    net.sf.ehcache.hibernate.EhCacheRegionFactory
</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_structured_entries">true</property>     
<property name="hibernate.cache.generate_statistics">true</property>

这篇关于如何完全禁用Hibernate缓存? (在Spring 3中,带有注释的Hibernate)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆