Hibernate console failing with error

I have a spring + hibernate application. When trying to use the hibernate console, I keep getting the following error

hql> from Person
java.lang.RuntimeException: 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.impl.NoCachingRegionFactory.buildEntityRegion(NoCachingRegionFactory.java:70)
 at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:280)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1872)
 at com.intellij.hibernate.console3.remote.HibernateFacadeImpl$1.buildSessionFactory(HibernateFacadeImpl.java:23)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
 at sun.rmi.transport.Transport$1.run(Transport.java:177)
 at sun.rmi.transport.Transport$1.run(Transport.java:174)
 at java.security.AccessController.doPrivileged(Native Method)
 at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
 at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:553)
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:808)
 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:667)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
 at java.lang.Thread.run(Thread.java:722)
 at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:273)
 at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:251)
 at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:160)
 at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194)
 at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148)
 at $Proxy196.buildSessionFactory(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:601)
 at com.intellij.execution.rmi.RemoteUtil$2$1$1.compute(RemoteUtil.java:99)
 at com.intellij.execution.rmi.RemoteUtil.executeWithClassLoader(RemoteUtil.java:160)
 at com.intellij.execution.rmi.RemoteUtil$2$1.invoke(RemoteUtil.java:96)
 at $Proxy196.buildSessionFactory(Unknown Source)
 at com.intellij.hibernate.engine.HibernateEngine.ensureInitialized(HibernateEngine.java:117)
 at com.intellij.hibernate.engine.HibernateEngine.createQuery(HibernateEngine.java:141)
 at com.intellij.jpa.engine.JpaEngineBase.executeQueryInner(JpaEngineBase.java:166)
 at com.intellij.jpa.engine.JpaEngineBase.access$000(JpaEngineBase.java:44)
 at com.intellij.jpa.engine.JpaEngineBase$2.run(JpaEngineBase.java:128)
 at com.intellij.jpa.engine.JpaEngineBase$1.run(JpaEngineBase.java:95)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
 at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
 at java.util.concurrent.FutureTask.run(FutureTask.java:166)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
 at java.lang.Thread.run(Thread.java:722)

In my spring context file where hibernate is configured, I have second level cache turned on already. I also have a region factory class set.

<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>

Why does the hibernate console still fail with the above error?

Pls advice.

I am running current v12 (release version, build 123.72)

Thanks

3 comments
Comment actions Permalink

No answers to this???

0
Comment actions Permalink

What is your hibernate properties? I tried to reproduce this with:

<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>

And met the issue. But then I've added:

<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>

And console works.

Alexander.

0
Comment actions Permalink

Alex - Thanks! Adding that works.

As for recent ehcache releases, the preferred way to intergrate it as a 2LC with hibernate is

<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>

(as described here http://ehcache.org/documentation/integrations/hibernate)

You shouldn't need to specify

<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>

again. Doing that by passes ehcache as a cache provider of choice.

IDEA should be able to pick up on that fact and let the console work.

I already filed a ticket as of yesterday (http://youtrack.jetbrains.com/issue/IDEA-97393). I'll update it with this additional info.

Let me know if you have questions.

Thanks again

0

Please sign in to leave a comment.