【问题标题】:Ehcache integration with Hibernate & Spring Exception: Second-level cache is not enabled for usageEhcache 与 Hibernate & Spring Exception 的集成:二级缓存未启用使用
【发布时间】:2012-06-27 16:47:25
【问题描述】:

我将 Spring 3.1 与 Hibernate 4 一起使用。在将 Ehcache 与 Hibernate 一起使用时,出现如下错误:

二级缓存未启用使用 [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]

即使我将 second_level_cache 设置为 true,我仍然会遇到同样的错误。 这是我的定义,如果有人可以帮助我,我会很高兴。

感谢和问候,

T

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource"><ref local="dataSource"/></property>
    <property name="packagesToScan" value="com.tk.sample.ext4.model" />
    <property name="hibernateProperties">
    <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.use_sql_comments">true</prop>
        <prop key="hibernate.format_sql">false</prop>
        <prop key="hibernate.hbm2ddl.auto">update</prop>
        <prop key="hibernate.generate_statistics">true</prop>
        <prop key="current_session_context_class">thread</prop>
        <prop key="hibernate.connection.release_mode">auto</prop>
        <prop key="hibernate.auto_close_session">true</prop>
        <prop key="hibernate.transaction.flush_before_completion">true</prop>
        <prop key="hibernate.transaction.auto_close_session">true</prop>
        <prop key="hibernate.connection.characterEncoding">UTF-8</prop>
        <!-- c3p0 properties -->
        <prop key="hibernate.c3p0.min_size">2</prop>
        <prop key="hibernate.c3p0.max_size">50</prop>
        <prop key="hibernate.c3p0.timeout">300</prop>
        <prop key="hibernate.c3p0.max_statements">50</prop>
        <prop key="hibernate.c3p0.idle_test_period">3000</prop>
        <prop key="hibernate.c3p0.acquireRetryAttempts">30</prop>
        <prop key="hibernate.c3p0.acquireIncrement">5</prop>
        <prop key="hibernate.c3p0.initialPoolSize">2</prop>
        <prop key="hibernate.c3p0.maxPoolSize">50</prop>
        <prop key="hibernate.c3p0.maxIdleTime">300</prop>
        <prop key="hibernate.c3p0.maxStatements">50</prop>
        <prop key="hibernate.c3p0.minPoolSize">2</prop>
        <!-- Ehcache properties -->
        <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
        <prop key="hibernate.cache.provider_configuration_file_resource_path">/WEB-INF/ehcache.xml</prop>
        **<prop key="hibernate.cache.use_second_level_cache">true</prop>**
        <prop key="hibernate.cache.use_query_cache">true</prop>
        <prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
    </props>
    </property>
</bean>

ehcache.xml

  <ehcache>
  <diskStore path="java.io.tmpdir"/>
  <defaultCache
     maxEntriesLocalHeap="10000"
     eternal="false"
     timeToIdleSeconds="120"
     timeToLiveSeconds="120"
     overflowToDisk="true"
     maxEntriesLocalDisk="10000000"
     diskPersistent="false"
     diskExpiryThreadIntervalSeconds="120"
     memoryStoreEvictionPolicy="LRU"
  />
</ehcache>

【问题讨论】:

    标签: spring hibernate ehcache second-level-cache


    【解决方案1】:

    这在其他线程中也有讨论 删除以下行

    <prop key="hibernate.cache.provider_class">
    

    添加以下内容

    <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
    

    Hibernate 3 和 Hibernate 4 会有不同的配置。

    【讨论】:

    • 0 否决票 Ehcache 网络参考谈到了这个配置,我在其他线程和博客上看到了这个方法,但奇怪的是 hibernate 4 参考没有谈到 hibernate.cache.region.factory_class 并且他们维护旧属性 hibernate.cache.provider_class
    猜你喜欢
    • 1970-01-01
    • 2012-12-12
    • 2013-11-07
    • 2015-10-13
    • 2014-11-10
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多