whiteErru
whiteErru

Reputation: 275

hibernate 4.3.0 2 level cache configuration

In Hibernate version 3.X it's possible to configure 2 level cache in hibernate.cfg like this:

<property name="hibernate.cache.use_second_level_cache">true</property>

<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>

In version 4.3.0 there is no class EhCacheProvider in org.hibernate.cache package.

What is the workaround for this situation?

Thanks

Upvotes: 3

Views: 6343

Answers (2)

user3198259
user3198259

Reputation: 174

Add below depenedency in your pom.

<dependency>
 <groupId>org.hibernate</groupId>
 <artifactId>hibernate-core</artifactId>
 <version>4.1.9.Final</version>
</dependency>

<dependency>
 <groupId>org.hibernate</groupId>
 <artifactId>hibernate-ehcache</artifactId>
 <version>4.1.9.Final</version>
 <exclusions>
  <exclusion>
   <groupId>net.sf.ehcache</groupId>
   <artifactId>ehcache-core</artifactId>
  </exclusion>
 </exclusions>
</dependency>

Refer to this link: https://dzone.com/articles/hibernate-4-and-ehcache-higher

Upvotes: 1

Ashish Jagtap
Ashish Jagtap

Reputation: 2819

STEP 1 Add EHcache dependency

Hibernate ships with the ehcache library

1.1] Maven Dependency

add maven dependency for Ehcache in your application as

<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>[2.0.0]</version>
    <type>pom</type>
</dependency>

1.2] Download Jar file

If you are not using maven dependency you can download the jars file from Download URL add this jar file into lib directory and your project CLASSPATH.

STEP 2 Configuring EhCache

To configure ehcache, you need to do two steps:

2.1] configure Hibernate for second level caching

<property key="hibernate.cache.use_second_level_cache">true</property>

2.2] specify the second level cache provider

Hibernate 3.3 and above

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

Hibernate 3.2 and below

<property name="hibernate.cache.region.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>

hope this will help you !

Upvotes: 4

Related Questions