Does Hibernate 4 with ehcache require ehcache-core library?
Asked Answered
Z

2

9

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?

Zymometer answered 12/4, 2013 at 11:19 Comment(0)
H
20

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.

Haymo answered 10/7, 2013 at 19:41 Comment(1)
no,this is not rsolving the issue, i got ::**org.hibernate.HibernateException: could not instantiate RegionFactory [org.hibernate.cache.ehcache.EhCacheRegionFactory]Antecedents
O
0

Check if there any .properties file in your project like hsqlDatabaseConfig.properties, try to update the property as below

sessionFactory.hibernateProperties = hibernate.cache.use_second_level_cache=true\n\
                                     hibernate.cache.use_query_cache=true\n\
                              hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.internal.EhcacheRegionFactory\n\
Orangeism answered 20/8, 2019 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.