-->
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.  [ 1 post ] 
Author Message
 Post subject: Querycache /Second level cache for SQL not HQL
PostPosted: Sun Mar 29, 2009 2:52 pm 
Newbie

Joined: Tue Jan 31, 2006 8:00 am
Posts: 14
Hi All,

I am trying to get Query cache working for a SQL query not HQL.
No matter how many times I execute query, the query results just don't stick into the cache and for every subsequent invocation the cache lookup fails and ends up in a database roundtrip.

Let me what is missing here..

The query goes something like this
---------------------------------------------------
select value from from Xtable where id1=:id1 and id2=:id2 and id3=:id3 and type='T' and mtchCol=:txt
union
select value from from Xtable where id1=:id1 and id2=:id2 and id3=:id3 and type='HL' and hnbr>=:hnbr and lnbr<:lnbr
union
select value from from Xtable where id1=:id1 and id2=:id2 and id3=:id3 and type='H' and lnbr <:lnbr
union
select value from from Xtable where id1=:id1 and id2=:id2 and id3=:id3 and type='L' and hnbr>= :hnbr
---------------------------------------------------
SQLQuery query = (SQLQuery) session.createSQLQuery(sqlQuery).setCacheable(true).setCacheRegion("customCache");
Object result = query.addScalar("value",Hibernate.BIG_DECIMAL).uniqueResult();
---------------------------------------------------
hibernate.cfg.xml

<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="cache.provider_configuration_file_resource_path">ehcache.xml</property>
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
-----------------------------------------------------------
ehcache.xml

<ehcache>
<diskStore path="user.dir"/>

<cache name="customCache"
maxElementsInMemory="5500"
eternal="true"
overflowToDisk="true"
/>

</ehcache>
------------------------------------------------------------
Log response


starting query cache at region: customCache
2009-03-29T13:08:41.164Z WARN net.sf.ehcache.hibernate.EhCacheProvider[89]: Could not find a specific ehcache configuration for cache named [customCache]; using defaults.
2009-03-29T13:08:41.164Z DEBUG net.sf.ehcache.store.DiskStore[182]: Deleting data file customCache.data
2009-03-29T13:08:41.164Z DEBUG net.sf.ehcache.store.MemoryStore[73]: Initialized net.sf.ehcache.store.LruMemoryStore for customCache
2009-03-29T13:08:41.164Z DEBUG net.sf.ehcache.store.LruMemoryStore[71]: customCache Cache: Using SpoolingLinkedHashMap implementation
2009-03-29T13:08:41.164Z DEBUG net.sf.ehcache.Cache[429]: Initialised cache: customCache
2009-03-29T13:08:41.164Z DEBUG net.sf.ehcache.hibernate.EhCacheProvider[92]: started EHCache region: customCache
2009-03-29T13:08:41.164Z DEBUG org.hibernate.cache.StandardQueryCache[102]: checking cached query results in region: customCache
2009-03-29T13:08:41.180Z DEBUG net.sf.ehcache.hibernate.EhCache[77]: key: sql:
2009-03-29T13:08:41.180Z DEBUG net.sf.ehcache.store.MemoryStore[138]: customCacheCache: customCacheMemoryStore miss for sql: 1 ; parameters: ; named parameters: {}
2009-03-29T13:08:41.180Z DEBUG net.sf.ehcache.Cache[661]: customCache cache - Miss
2009-03-29T13:08:41.180Z DEBUG org.hibernate.cache.StandardQueryCache[107]: query results were not found in cache


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

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.