如何在 persistence.xml 文件中禁用 ehcache
全部, 是否可以在我的持久性 xml 文件中禁用二级缓存? 我有一个使用 ehcache 的 Spring+Hibernate+JPA 配置。在我的 persistence.xml 文件中,我有这样的条目:
<property name="hibernate.cache.use_second_level_cache" value="false"/>
但这似乎不起作用,并且随着我的应用程序运行,我仍然看到加载的实体数量不断增加。我用这个获取统计数据:
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
EntityManagerFactory emf = emfi.getNativeEntityManagerFactory();
EntityManagerFactoryImpl empImpl = (EntityManagerFactoryImpl)emf;
log.debug(empImpl.getSessionFactory().getStatistics());
请帮忙。
All,
is it possible to disable secondary cache in my persistence xml file?
I have a Spring+Hibernate+JPA configuration that uses ehcache. In my persistence.xml file I have this entry:
<property name="hibernate.cache.use_second_level_cache" value="false"/>
but this does not seem to work, and I still see the number of entities loaded keeps on increasing, as my application runs. I fetch the statistics using this:
EntityManagerFactoryInfo emfi = (EntityManagerFactoryInfo) entityManagerFactory;
EntityManagerFactory emf = emfi.getNativeEntityManagerFactory();
EntityManagerFactoryImpl empImpl = (EntityManagerFactoryImpl)emf;
log.debug(empImpl.getSessionFactory().getStatistics());
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在查看的统计数据是 Hibernate 会话缓存(第一级缓存)。您的二级缓存 (ehcache) 已禁用。您所经历的是正常行为。
编辑:
启用 ehcache 后,您会发现如下日志条目:(
如果您启用包的日志记录 - 缓存提供程序可能会有所不同,例如可能
net.sf.ehcache.hibernate.EhCacheRegionFactory
- 不知道你用什么)The statistics you are looking at is the Hibernate session cache (the 1st level cache). Your 2nd level cache (ehcache) is disabled. What you experience is the normal behaviour.
EDIT:
When ehcache is enabled you would find log entries like:
(provided you enable logging for the package - the cache provider may vary e.g. maybe
net.sf.ehcache.hibernate.EhCacheRegionFactory
- don't know what you use)