Question

Below an illustration of my project hierarchy

project hierarchy
(source: yfrog.com)

When i try to connect my file_name.java file to hibernate i'm getting these errors

Exception in thread "main" org.hibernate.HibernateException: Could not instantiate cache implementation
    at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:214)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1218)
    at net.pkg.dao.FirstExample.main(FirstExample.java:17)
Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
    at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:21)
    at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:61)

the problem has something to do with my hibernate.cfg.xml... but I'm unable to resolve it. Any ideas?

Was it helpful?

Solution

I suspect that you are using either @Cacheable or @Cache on your entities without having the second level cache activated, hence the error message:

o.h.c.NoCachingEnabledException: Second-level cache is not enabled for usage ...

You need something like this in the hibernate.cfg.xml to use the second level cache (I'm using EHCache as cache provider here):

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

Whether you really need the second level cache is another story.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top