我有Hibernate ehcache 4.1.4 final,ehcache-3.3.0.jar
config(spring 3.2)for hibernate 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 {
...
我的道歉
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);
}
构建和部署Succesfull,但此cacheEntries == null sessionFactory.getStatistics()方法LOGSUMMARY();是空的
SecondLevelCacheStatistics cacheEntries = sessionFactory.getStatistics()
.getSecondLevelCacheStatistics("");
sessionFactory.getStatistics().logSummary();
答案 0 :(得分:1)
你似乎没有具体问题,但我已经可以说一件事了。
由于您使用的是Ehcache 3.3,因此您应该通过JCache配置Ehcache,而不是为Ehcache 2创建的EhCacheRegionFactory
。
另外,你应该使用经典的类名(以大写字母开头,然后是小写字母)。对于读你的人来说,这有点误导。
答案 1 :(得分:0)
这是我的坏事。 首先,我将lib ehcache-3.3.0.jar更改为更低的ehcache-core-2.6.10。 其次我添加到实体@Cacheable注释,但我不确定它是否有用。