我已经配置了ehcache.xml
在spring里也已经配置了<prop key="hibernate.cache.use_query_cache">true</prop>
    <prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
    </prop>
在hbm.xml里也已经配置了<cache usage="read-only"/>但是还是出错:Caused by: java.lang.IllegalAccessError: tried to access method net.sf.ehcache.CacheManager.<init>()V from class org.hibernate.cache.EhCacheProvider请问谁知道错在哪呢?

解决方案 »

  1.   

    应该是版本的问题
    你目前使用的版本是多少?
    找个新的ehcache版本
      

  2.   

    http://download.csdn.net/source/229883
    我是在csdn下的,说是1.3版本
      

  3.   

    我换了1.24版本没问题了
    但是设置了setCacheable(true)怎么没有效果啊
    2次查询都是SQL语句向数据库直接查询的
      

  4.   

    有加的,现在的情况是
    在同一个方法里,使用查询,关闭session,再开,查询,确实是缓存生效了,没有直接连接数据库
    但是,在实际应用中,2次调用查询方法,那还是2次SQL连接数据库直接查询的
      

  5.   


    <property name="url"> <value>jdbc:mysql://localhost:3306/pingbsn </value> </property> <property name="username"> <value>root </value> </property> <property name="password"> <value>admin </value> </property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref bean="datasource" /> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider </prop> <prop key="hibernate.show_sql">false </prop>     <prop key="hibernate.cache.use_query_cache">true </prop>     <prop key="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml </prop> <prop key="connection.provider_class">org.hibernate.connection.DatasourceConnectionProvider </prop> </props> </property> <property name="mappingResources"> <list> <value> com/typingsoft/kwlprint/dao/Userinfo.hbm.xml </value> </list> </property> </bean> <bean id="UserinfoDAO" class="com.typingsoft.kwlprint.dao.UserinfoDAO"> <property name="sessionFactory"> <ref bean="sessionFactory" /> </property> </bean> <bean name="/user" class="com.typingsoft.kwlprint.struts.action.UserAction"> <property name="userDao"> <ref bean="UserinfoDAO"/> </property> </bean> <bean name="/lookupUser" class="com.typingsoft.kwlprint.struts.action.LookupUserAction"> <property name="userDao"> <ref bean="UserinfoDAO"/> </property> </bean> </beans> hbm.xml文件: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!--     Mapping file autogenerated by MyEclipse - Hibernate Tools --> <hibernate-mapping>     <class name="com.typingsoft.kwlprint.dao.Userinfo" table="userinfo" catalog="pingbsn">       <cache usage="read-write" region="com.typingsoft.kwlprint.dao.Userinfo" />         <id name="id" type="java.lang.Long">             <column name="id" />             <generator class="native" />         </id>                 <property name="name" type="java.lang.String">             <column name="name" length="50" not-null="true" />         </property>         <property name="password" type="java.lang.String">             <column name="password" length="20" />         </property>     </class> </hibernate-mapping> ehcache文件: <?xml version="1.0" encoding="UTF-8"?> <ehcache> <diskStore path="java.io.tmpdir"/> <defaultCache maxElementsInMemory="10000" eternal="false" overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="180" diskPersistent="false"/> <cache name="com.typingsoft.kwlprint.dao.Userinfo" maxElementsInMemory="10000" eternal="false"  timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" /> <cache name="org.hibernate.cache.StandardQueryCache"       maxElementsInMemory="50"       eternal="false"       timeToIdleSeconds="3600"       timeToLiveSeconds="7200"       overflowToDisk="true"/>             <!-- 设置时间戳缓存的数据过期策略 -->     <cache name="org.hibernate.cache.UpdateTimestampsCache"       maxElementsInMemory="5000"       eternal="true"       overflowToDisk="true"/>         <!-- 设置自定义命名查询缓存customerQueries的数据过期策略 -->     <cache name="myCacheRegion"         maxElementsInMemory="1000"         eternal="false"         timeToIdleSeconds="300"         timeToLiveSeconds="600"         overflowToDisk="true"         /> </ehcache> action里代码: