java ehcache 休眠 4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13882393/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ehcache hibernate 4
提问by chris
In my application I use the hibernate-core-4.1.8 jar and would like to take an ehCache as 2nd level cache. The jar I am currently using is ehcache-core-2.5.0. I placed it in my WebContetn/WEB-INF/lib folder and put it in the classpath too.
在我的应用程序中,我使用 hibernate-core-4.1.8 jar 并希望将 ehCache 作为二级缓存。我目前使用的 jar 是 ehcache-core-2.5.0。我将它放在我的 WebContetn/WEB-INF/lib 文件夹中,并将它也放在类路径中。
My hibernate.cfg.xml looks like this:
我的 hibernate.cfg.xml 看起来像这样:
<hibernate-configuration>
<session-factory>
....
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
</session-factory>
</hibernate-configuration>
the ehcache.xml which is placed in the JavaResources/src folder:
位于 JavaResources/src 文件夹中的 ehcache.xml:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true"
monitoring="autodetect" dynamicConfig="true">
<defaultCache
maxElementsInMemory="100000"
eternal="false"
timeToIdleSeconds="1000"
timeToLiveSeconds="1000"
overflowToDisk="false"
/>
</ehcache>
When running my application the class org.hibernate.cache.ehcache.EhCacheRegionFactory is not found:
运行我的应用程序时,找不到类 org.hibernate.cache.ehcache.EhCacheRegionFactory:
java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.ehcache.EhCacheRegionFactory
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.findClass(ClassLoaderServiceImpl.java:99)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:444)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:275)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2283)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2279)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1748)
at creator.controllers.MyFactory.<clinit>(MyFactory.java:18)
at creator.controllers.SchoolDAO.getList(SchoolDAO.java:98)
.....
回答by ant
you need to include hibernate-ehcache.jar
by downloading itor is you're using maven put it in your dependencies like this
您需要hibernate-ehcache.jar
通过下载来包含它,或者您正在使用 maven 将它像这样放入您的依赖项中
<dependency>
<artifactId>hibernate-ehcache</artifactId>
<groupId>org.hibernate</groupId>
<version>4.0.0.CR6</version>
</dependency>