Why is EhCacheProvider deprecated?

Viewed 27688

I am configuring my hibernate project to use a 2nd-level cache provider, so that I can take advantage of query caching.

I added a dependency to ehcache:

   <dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>2.2.0</version>
   </dependency>

I think that the provider class I want to use is:

net.sf.ehcache.hibernateEhCacheProvider

When I look at the referenced libraries in eclipse, I see the @Deprecated annotation on EhCacheProvider, and also on SingletonEhCacheProvider. What gives? Is there an up-to-date replacement provider that I can use?

I am using hibernate version 3.4.0.GA, in case it matters.

4 Answers

EhCache 2 is now deprecated and discontinued. You should use EhCache 3 instead. In Hibernate versions after 5.3 it is recommended to use JSR-107 (JCache). In order to do that 2 dependencies are needed:

<dependency>
     <groupId>org.hibernate</groupId>
     <artifactId>hibernate-jcache</artifactId>
     <version>your_hibernate_version</version>
</dependency>

<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>3.6.3</version>
    <scope>runtime</scope>
</dependency>

The first one provides JSR-107 API compliant with Hibernate. The second one is actual cache implementation - EhCache 3.

Also new RegionFactory must be used:

hibernate.cache.region.factory_class=org.hibernate.cache.jcache.JCacheRegionFactory
Related