【问题标题】:Second level cache config二级缓存配置
【发布时间】:2017-03-01 05:53:26
【问题描述】:

我有 Hibernate ehcache 4.1.4 final,ehcache-3.3.0.jar

用于休眠 ehcache 的配置(spring 3.2)

 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);
}

构建和部署成功,但是这个 cacheEntries==null sessionFactory.getStatistics().logSummary();是空的

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

【问题讨论】:

    标签: hibernate ehcache


    【解决方案1】:

    您在这里似乎没有具体问题,但我已经可以说一件事了。

    由于您使用的是 Ehcache 3.3,因此您应该通过 JCache 配置 Ehcache,而不是为 Ehcache 2 制作的 EhCacheRegionFactory

    此外,您应该真正使用经典的类名(以大写字母开头,然后是小写字母)。目前对于阅读您的人来说有点误导。

    【讨论】:

      【解决方案2】:

      这是我的错。 首先,我将 lib ehcache-3.3.0.jar 更改为较低的 ehcache-core-2.6.10。 其次,我添加到实体 @Cacheable 注释,但我不确定它是否有帮助。

      【讨论】:

        猜你喜欢
        • 2014-09-11
        • 2014-10-18
        • 2012-04-02
        • 2014-06-28
        • 2014-06-21
        • 1970-01-01
        • 1970-01-01
        • 2015-09-07
        • 1970-01-01
        相关资源
        最近更新 更多