How to enable second level cache in Hibernate
This is what you need to do:
Set the following Hibernate properties:
<property name="hibernate.cache.use_second_level_cache">true</property> <property name="hibernate.cache.provider_class">ehcache</property>
Add an ehcache.xml file in your classpath, containing the cache configuration entries:
<cache name="com.mycompany.MyEntity" maxElementsInMemory="50" eternal="true" overflowToDisk="false" timeToIdleSeconds="600" timeToLiveSeconds="600" diskPersistent="false" memoryStoreEvictionPolicy="LRU" />
Define the Caching type for each entity:
@Entity @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) public class MyEntity { ... }