Spring Boot + JPA2 + Hibernate - enable second level cache

前端 未结 6 2141
悲&欢浪女
悲&欢浪女 2020-12-02 09:35

I\'m using Spring Boot 1.2.5 with JPA2 to annotate entities (and hibernate as underlaying JPA implementation).

I wanted to use second level cache in that setup, so e

6条回答
  •  一个人的身影
    2020-12-02 10:00

    @Daimon I am not really sure, whether

    spring.jpa.properties.javax.persistence.sharedCache.mode=ALL
    

    is the best decision.

    Quoted from Hibernate 20.2.1. Cache mappings documentation section

    By default, entities are not part of the second level cache and we recommend you to stick to this setting. However, you can override this by setting the shared-cache-mode element in your persistence.xml file or by using the javax.persistence.sharedCache.mode property in your configuration.

    whereas

    ENABLE_SELECTIVE (Default and recommended value): entities are not cached unless explicitly marked as cacheable.

    So, could it be, that you have not annotated all affected entities with @javax.persistence.Cacheable or rather @org.hibernate.annotations.Cache ? This could lead to the affect, that the Query Cache tried to look up the affected entities in the Second Level Cache without success and then started to fetch each entity by a single select.

提交回复
热议问题