ehcache休眠4 [英] ehcache hibernate 4

查看:114
本文介绍了ehcache休眠4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用了hibernate-core-4.1.8 jar,并希望将ehCache作为二级缓存。
我目前使用的jar是ehcache-core-2.5.0。我将它放在我的WebContetn / WEB-INF / lib文件夹中,并将其放入classpath中。

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.cfg.xml如下所示:

My hibernate.cfg.xml looks like this:

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

位于JavaResources / src文件夹中的ehcache.xml:

the ehcache.xml which is placed in the JavaResources/src folder:

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

运行我的应用程序时,未找到类org.hibernate.cache.ehcache.EhCacheRegionFactory:

When running my application the class org.hibernate.cache.ehcache.EhCacheRegionFactory is not found:

java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.ehcache.EhCacheRegionFactory
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.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)
    .....


推荐答案

您需要包含 hibernate -ehcache.jar 下载它,或者你正在使用maven把它放入你的依赖关系中,像这样

you need to include hibernate-ehcache.jar by downloading it or is you're using maven put it in your dependencies like this

<dependency>
<artifactId>hibernate-ehcache</artifactId>
<groupId>org.hibernate</groupId>
<version>4.0.0.CR6</version>
</dependency>

这篇关于ehcache休眠4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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