Kasyap
Kasyap

Reputation: 43

I am not able to configure ehcache with hibernate

corresponding jar files i used are below :

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.

Upvotes: 1

Views: 2559

Answers (2)

Henri
Henri

Reputation: 5711

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.

Upvotes: 6

Maciej Kowalski
Maciej Kowalski

Reputation: 26492

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>

Upvotes: -2

Related Questions