2017-03-01 81 views
0

我有休眠的Ehcache 4.1.4最終的Ehcache-3.3.0.jar二級緩存配置

配置(春季3.2)用於冬眠的Ehcache

hibernate.cache.use_second_level_cache=true  
      hibernate.generate_statistics=true   
      hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory 

我的實體

@Entity 
@Table(name = "SESSION_ENTERING") 
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY) 
public class SESSION_ENTERING implements Serializable { 
... 

My dao

public List<SESSION_ENTERING> getSESSIONS() { 
    return sessionFactory.getCurrentSession(). 
      createQuery("from SESSION_ENTERING order by id desc") 
      .setCacheable(true) 
      .list(); 
} 
    //or even this 
    public SESSION_ENTERING getSESSION() { 
     return SESSION_ENTERING)sessionFactory.getCurrentSession().get(SESSION_ENTERING.class,256l); 
} 

Build and Depl oy Succesfull,但是這個cacheEntries == null sessionFactory.getStatistics()。logSummary();是空的

 SecondLevelCacheStatistics cacheEntries = sessionFactory.getStatistics() 
    .getSecondLevelCacheStatistics(""); 
    sessionFactory.getStatistics().logSummary(); 

回答

1

你在這裏似乎沒有具體問題,但我已經可以說一件事了。

由於您使用的Ehcache 3.3,你應該通過配置的JCache代替了Ehcache這是對的Ehcache取得2

另外,EhCacheRegionFactory的,你應該使用經典的類名(從大寫字母,然後下案件)。目前有人讀到你有點誤導。

0

這是我的壞。 首先,我更改了lib ehcache-3.3.0.jar以獲取更低版本的ehcache-core-2.6.10。 第二我添加到實體@Cacheable註釋,但我不知道它是否有用。