-->
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.  [ 3 posts ] 
Author Message
 Post subject: EHCache vs Native Query
PostPosted: Mon Jul 23, 2007 1:56 pm 
Newbie

Joined: Mon Jul 23, 2007 1:43 pm
Posts: 1
Hi Hibernate Experts,

I am having problem applying the cache when using Native Query that returns non entity objects.

When I see the log, it said:

DEBUG 2007-07-23 18:56:47,050 org.hibernate.cache.StandardQueryCache - checking cached query results in region: query.abc
DEBUG 2007-07-23 18:56:47,050 org.hibernate.cache.EhCache - key: sql: SELECT as_id AS articleId ..... (truncated by me)
DEBUG 2007-07-23 18:56:47,050 org.hibernate.cache.StandardQueryCache - query results were not found in cache
DEBUG 2007-07-23 18:56:47,394 org.hibernate.cache.StandardQueryCache - caching query results in region: query.abc; timestamp=4854619369676800

....
....
that's ok, first try - the cache should not be there
....

but again i execute the same url, the logs repeat with the same message, that it said query results were not found in cache.

Here is the piece of codes which executing the query:

return getHibernateTemplate().executeFind(
new HibernateCallback() {

public Object doInHibernate(Session session) throws HibernateException, SQLException {
Query query = session.getNamedQuery("myquery");

query.setParameter("A", a)
.setParameter("siteId", siteId)
.setCacheable(true) .setCacheRegion("query.abc") .setResultTransformer(Transformers.aliasToBean(MyResult.class));

return query.list();
}
}
);


and the region configuration:

<cache name="query.abc"
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="14400"
timeToLiveSeconds="14400"
overflowToDisk="true"
/>

Now my question what is wrong? do i miss something? or is Hibernate able to cache result from Native sql and the results are basically not an entity?

Thank you :)


Top
 Profile  
 
 Post subject: Re: EHCache vs Native Query
PostPosted: Tue Jun 22, 2010 5:03 pm 
Newbie

Joined: Thu Jun 17, 2010 12:05 pm
Posts: 3
If you look at the org.hibernate.cache logs you'll see you're creating a new transformer object each time you call the query which will make the query unique.

You can create a one time static var for the class and use that for the queries and you should get hits


Top
 Profile  
 
 Post subject: Re: EHCache vs Native Query
PostPosted: Wed Sep 22, 2010 6:32 am 
Newbie

Joined: Wed Sep 22, 2010 6:27 am
Posts: 3
HI dgrossen,
Can you please post a sample code how to solve the problem, like I am in the same situation where I am not able to cache the query results if I have native sql with result transformer. Following your advice you had asked create static class, but I am not really sure how to do. Can you please share any sample code regards to it.
Best Regards
NG


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.