Why is EhCacheProvider deprecated?

What gives? Is there an up-to-date replacement provider that I can use?

They have been deprecated in favor of the classes implementing the new Hibernate 3.3/3.5 SPI with its CacheRegionFactory. These implementations are respectively:

  • net.sf.ehcache.hibernate.EhCacheRegionFactory
  • net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory

Benefits of the new SPI include:

  • The SPI removed synchronization in the Hibernate cache plumbing. It is left up to the caching implementation on how to control concurrent access. Ehcache, starting with 1.6, removed syncrhonization in favour of a CAS approach. The results, for heavy workloads are impressive.
  • The new SPI provides finer grained control over cache region storage and cache strategies. Ehcache 2.0 takes advantage of this to reduce memory use. It provides read only, nonstrict read write and read write strategies, all cluster safe.
  • Ehcache 2.0 is readily distributable with Terracotta Server Array. This gives you cluster safe operation (coherency), HA and scale beyond the limits of an in-process cache, which is how most Hibernate users use Ehcache today. There is the existing ehcache.jar and ehcache-terracotta.jar which provides the client library. (...)

You are thus encouraged to use the new implementations. Configuration is done via the following property:

<property name="hibernate.cache.region.factory_class">
    net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
</property>

That replaces the hibernate.cache.provider_class property.

References

  • Hibernate Blog
    • Ehcache 2.0 supports new Hibernate 3.3 caching provider
  • EhCache documentation
    • Upgrading From Ehcache versions prior to 2.0
    • Hibernate Second Level Cache

if you wish to use Hibernate 4.0.0.Final. for the value of hibernate.cache.region.factory_class property use:

  • org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory instead of net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory and
  • org.hibernate.cache.ehcache.EhCacheRegionFactory instead of net.sf.ehcache.hibernate.EhCacheRegionFactory

Otherwise you will end up with some internal ClassNotFound exceptions