Hibernate SpringCache is a Hibernate cache implementation that backs to the Spring Cache abstraction. In other words, setup caching once in Spring then use it from Spring and Hibernate so configuration isn't duplicated.
This project has been submitted to Hibernate for inclusion: hibernate/hibernate-orm#1639
- Minimum requirements — You'll need Java 1.8+, Hibernate 5.3.3+, and Spring 4.3+. Spring Boot 1.4+ is optional. Use version 1.x of this project for Hibernate 5.2 support.
- Download — Depend on this libary using, for example, Maven:
<dependency>
<groupId>com.integralblue</groupId>
<artifactId>hibernate-springcache</artifactId>
<version>[INSERT VERSION HERE]</version>
<type>jar</type>
</dependency>
- In application.properties, add:
spring.jpa.properties.hibernate.cache.region.factory_class=com.integralblue.hibernate.cache.springcache.SpringCacheRegionFactory
- If using Spring Boot, that's it -
com.integralblue.hibernate.cache.springcache.SpringCacheRegionFactoryAutoConfigure
will take care of the rest. - If not not using Spring boot, the
com.integralblue.hibernate.cache.springcache.SpringCacheRegionFactoryBeanPostProcessor
bean post processor must be registered (add it as a bean using Spring Java or XML configuration).