【问题标题】:second level cache configuration with hibernate 4.xhibernate 4.x 的二级缓存配置
【发布时间】:2014-08-13 05:43:53
【问题描述】:

我在 hibernate4 中配置了 ehcache 以下是我的配置

pom.xml

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>4.0.1.Final</version>
</dependency>

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-ehcache</artifactId>
  <version>4.0.1.Final</version>
</dependency>

休眠配置

configuration.setProperty("hibernate.cache.region.factory_class",
                "org.hibernate.cache.ehcache.EhCacheRegionFactory");
configuration.setProperty("hibernate.cache.region.factory_class",
                "org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory");
configuration.setProperty("hibernate.cache.use_second_level_cache", "true");
configuration.setProperty("hibernate.cache.use_query_cache", "true");

实体类

 @Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
@Cacheable




**Note : **
I did this configuration but  i am not getting any error, and ehcache is not working

【问题讨论】:

    标签: hibernate ehcache


    【解决方案1】:

    下面试试

    configuration.setProperty("hibernate.cache.region.factory_class",
                    "org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory");
    configuration.setProperty("hibernate.cache.use_second_level_cache", "true");
    configuration.setProperty("hibernate.cache.use_query_cache", "true");
    
    ehcache.hibernate.cache.provider_configuration=classpath:ehcache.xml
    

    ehcache.xml

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="ehcache.xsd"
             updateCheck="false" monitoring="autodetect"
             dynamicConfig="true">
    
     <diskStore path="java.io.tmpdir"/>
    
     <transactionManagerLookup class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup"
                                  properties="jndiName=java:/TransactionManager" propertySeparator=";"/>
    
      <cacheManagerEventListenerFactory class="" properties=""/>
    
         <defaultCache
                    maxElementsInMemory="10000"
                    eternal="false"
                    timeToIdleSeconds="120"
                    timeToLiveSeconds="120"
                    overflowToDisk="true"
                    diskSpoolBufferSizeMB="30"
                    maxElementsOnDisk="10000000"
                    diskPersistent="false"
                    diskExpiryThreadIntervalSeconds="120"
                    memoryStoreEvictionPolicy="LRU"
                    statistics="false"/>
            </ehcache>
    

    【讨论】:

      猜你喜欢
      • 2016-04-19
      • 2014-09-11
      • 2014-10-18
      • 1970-01-01
      • 2014-08-27
      • 1970-01-01
      • 2015-09-07
      • 1970-01-01
      • 2015-05-14
      相关资源
      最近更新 更多