Spring Boot + JPA2 + Hibernate - enable second level cache

前端 未结 6 2136
悲&欢浪女
悲&欢浪女 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:06

    You should have an ehcache.xml file in your classpath. The file should contains at least the default cache strategy. For easier debuging, make it eternal to be sure entities are not evicted from cache :

    ehcache.xml:

    
    
    
    
    
    

    To ensure that all is ok, you should have the following log during your application startup :

    Could not find a specific ehcache configuration for cache named [com.yourcompany.YourClass]; Using defaults.
    

    That means that your entity cache annotation have been correctly readed and default cache will be used.

    If you test with entityManager.find(Clazz.class, pk) that's not envolve the query cache, but just the entity cache. Query cache is used for queries (em.createQuery(...) and for relations ship

    Also, I use org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory, but I don't know wich is better.

提交回复
热议问题