开发者

How to disable ehcache in persistence.xml file

开发者 https://www.devze.com 2023-04-11 10:07 出处:网络
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:

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. 开发者_JAVA技巧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.


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:

[#|...|INFO|sun-appserver2.1|org.hibernate.cfg.SettingsFactory|...|Second-level cache: enabled|#]
[#|...|INFO|sun-appserver2.1|org.hibernate.cfg.SettingsFactory|...|Cache provider: org.hibernate.cache.EhCacheProvider|#]

(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)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号