1

corresponding jar files i used are below :

  • ehcache-3.2.0
  • hibernate-ehcache-5.0.2.Final
  • hibernate-core-5.0.2.Final

configuration is like this :

  <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> 
 <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
 <prop key="hibernate.cache.use_second_level_cache" >true</prop>
 <prop key="hibernate.cache.use_query_cache">true</prop>
 <prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop>

I am getting error like this :

java.lang.NoClassDefFoundError: net/sf/ehcache/CacheException

help me to getout of this issue.

Kasyap
  • 43
  • 1
  • 1
  • 11

2 Answers2

6

You are using Ehcache 3 (which is good) but are using a region factory that is Ehcache 2 compatible.

For Ehcache 3, which is JCache compliant, you should use org.hibernate.cache.jcache.JCacheRegionFactory.

You will find a full example here: https://github.com/ehcache/ehcache3-samples/tree/master/fullstack. Have a look at the README.md to find the interesting files.

Note: As Louis mentioned in the comment, you need Hibernate 5.2 to get JCache support.

Henri
  • 5,551
  • 1
  • 22
  • 29
-2

I think you need this artifact:

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

It contains the net.sf.ehcache packages / classes that your application is looking for.

Based on your hibernate property:

<prop key="net.sf.ehcache.configurationResourceName">/ehcache.xml</prop>
Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63