These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]

Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Caching SQL query problem
PostPosted: Thu Aug 30, 2007 4:49 am 

Joined: Thu Aug 30, 2007 4:29 am
Posts: 1

I got a problem during enabling caching for normal sql query using hibernate.

I did all configuration needed for enabling caching (EHCache) and it works correctly using hql (createQuery).

If i change query for normal sql query i got exception (ArrayIndexOutOfBound) like below.

Changing <prop key="hibernate.cache.use_query_cache">true</prop> to false there is no exception but also no caching ;).

Have you any idea to solve this problem?

Hibernate version:
3.1.3, 3.2.5.ga

Code between sessionFactory.openSession() and session.close():

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

hibernateSession.createSQLQuery("select * from cm_item_definitions").setCacheable(true).list();

Full stack trace of any exception that occurs:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at org.hibernate.type.TypeFactory.disassemble(TypeFactory.java:451)
at org.hibernate.cache.StandardQueryCache.put(StandardQueryCache.java:83)
at org.hibernate.loader.Loader.putResultInQueryCache(Loader.java:2194)
at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2138)
at org.hibernate.loader.Loader.list(Loader.java:2096)
at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:289)
at org.hibernate.impl.SessionImpl.listCustomQuery(SessionImpl.java:1695)
at org.hibernate.impl.AbstractSessionImpl.list(AbstractSessionImpl.java:142)
at org.hibernate.impl.SQLQueryImpl.list(SQLQueryImpl.java:152)

Name and version of the database you are using:
postgres 8, oracle 9

The generated SQL (show_sql=true):

select * from cm_item_definitions


 Post subject: Re: Caching SQL query problem
PostPosted: Thu Aug 30, 2007 5:47 pm 

Joined: Tue Oct 10, 2006 3:23 am
Posts: 33
That's because the aim of the second level cache is to (ultimately) cache entities that Hib knows about. I haven't verified this but I'm not surprised that caching sql query doesn't work as those are not (directly) translated by hibernate into entities.

It would be easy enough to take a cache provider, like eh and add the result set to the cache..

* rate if this helps *

 Post subject:
PostPosted: Wed Jan 09, 2008 1:30 pm 

Joined: Wed Jan 09, 2008 1:24 pm
Posts: 1
Hi Sebastian

I had this problem too. It's solutioned adding column's types to the query, using the method "addScalar()"

 Post subject: good tip
PostPosted: Mon Mar 16, 2009 8:15 am 

Joined: Mon Sep 08, 2008 5:09 am
Posts: 6
Location: Cluj-Napoca
The idea with using addScalar worked also for me.
it looks like a good solution.


Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.