加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

弹出启动JPA2 Hibernate – 启用二级缓存

发布时间:2020-12-14 16:45:58 所属栏目:Java 来源:网络整理
导读:我使用 Spring Boot 1.2.5与JPA2注释实体(和hibernate作为底层JPA实现). 我想在该设置中使用二级缓存,所以实体用@ javax.persistence.Cacheable注释 我还在application.properties中添加了以下内容: spring.jpa.properties.hibernate.cache.use_second_leve
我使用 Spring Boot 1.2.5与JPA2注释实体(和hibernate作为底层JPA实现).

我想在该设置中使用二级缓存,所以实体用@ javax.persistence.Cacheable注释

我还在application.properties中添加了以下内容:

spring.jpa.properties.hibernate.cache.use_second_level_cache=true
spring.jpa.properties.hibernate.cache.use_query_cache=true
spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory

在启动过程中,hibernate抱怨缺少EhCacheRegionFactory,所以我也把它添加到了pom:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-ehcache</artifactId>
</dependency>

但是,像entityManager.find(Clazz.class,pk)这样的查询仍然是触发数据库查询,而不是使用缓存的数据.

任何想法什么是失踪?

解决方法

那么在一些更多的挖掘这里是我在application.properties中缺少的东西:
spring.jpa.properties.javax.persistence.sharedCache.mode=ALL

希望它帮助某人:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读