Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Hibernate 4 with ehcache require ehcache-core library?

I am attempting to upgrade an appliaction from Hibernate 3 to Hibernate 4. The application uses ehcache.

When upgrading to Hibernate 4.2.0.Final I added a dependency on hibernate-ehcache-4.2.0.Final as suggested.

When I started up the application I received the following error:

Caused by: java.lang.NoClassDefFoundError: org/hibernate/cache/TimestampsRegion

According to http://www.javacraft.org/2012/03/migrate-to-hibernate-4-ehcache.html I should remove the dependency on ehcache-core and only use the hibernate provided jar to resolve this error.

Now, if I follow these instructions and remove this dependency my application which uses the net.sf.ehcache.CacheManager no-longer compiles.

// For example, this no-longer works
CacheManager manager = CacheManager.getInstance();

So my question is, can I use both libraries and continue working as before (Without updating the app), or do I have to change the app, in which case does hibernate-ehcache even provide the functionality required to access the cache?

like image 325
John Dalton Avatar asked Apr 12 '13 11:04

John Dalton


People also ask

Does hibernate use Ehcache?

Ehcache as a plug-in second-level cache for Hibernate – Automatically cache common queries in memory to substantially lower latency.

What is Ehcache library used for?

JAVA'S MOST WIDELY-USED CACHE Ehcache is an open source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. It's the most widely-used Java-based cache because it's robust, proven, full-featured, and integrates with other popular libraries and frameworks.

How does Ehcache work internally?

The cache acts as a local copy of data retrieved from or stored to the system-of-record. This is often a traditional database, although it may be a specialized file system or some other reliable long-term storage. For the purposes of using Ehcache, the SOR is assumed to be a database.


1 Answers

When using Hibernate 4 you have to use the org.hibernate packaged classes. The net.sf.ehcache ones are target at Hibernate 3.

Form 4 they have ported to 4 within the Hibernate repo directly (which is the most sensible thing in our opinion).

So using org.hibernate.cache.ehcache.EhCacheRegionFactory should solve your problem.

like image 135
Ramesh Kotha Avatar answered Sep 20 '22 15:09

Ramesh Kotha