I\'m working with a spring project using hibernate and look to implement second-level cache using ehcache. I see a number of approaches to this:
spring-mod
Our project uses option 3. We apply annotation org.hibernate.annotations.Cache to entities that we cache in an Ehcache, configure Ehcache using ehcache.xml, and enable and configure the Hibernate second-level cache in hibernate.cfg.xml:
net.sf.ehcache.hibernate.EhCacheProvider
net.sf.ehcache.hibernate.EhCacheRegionFactory
true
true
true
true
For most entities, we use cache concurrency strategy CacheConcurrencyStrategy.TRANSACTIONAL:
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
Our Maven project uses Hibernate 3.3.2GA and Ehcache 2.2.0:
net.sf.ehcache
ehcache-core
2.2.0
org.hibernate
hibernate-core
3.3.2.GA
org.hibernate
hibernate-commons-annotations
3.3.0.ga
net.sf.ehcache
ehcache
org.hibernate
hibernate-annotations
3.2.1.ga
org.hibernate
ejb3-persistence
3.3.2.Beta1