-->
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: Understanding how to use complicated queries
PostPosted: Sun Feb 21, 2010 6:25 am 
Beginner
Beginner

Joined: Sun Jan 24, 2010 3:04 am
Posts: 20
Hi!

I have the following query to execute:
select sum(price) from spot where job_id=? and id in (select id from status where job_id=? group by spot_event_id)

i have the following objects:
spot
status

Should i create the query with Query query = session.createQuery?

as well, what does it mean setCacheable on the query?when can i flush this cacheable?


Top
 Profile  
 
 Post subject: Re: Understanding how to use complicated queries
PostPosted: Mon Feb 22, 2010 12:27 pm 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
select sum(price) from spot where job_id=? and id in (select id from status where job_id=? group by spot_event_id)


A join-query might be more performant.
Something like:
Code:
select sum(price) from spot , status
WHERE spot.job_id = status.job_id AND spot.id=status.id AND   spot.job_id = ?


Quote:
Should i create the query with Query query = session.createQuery?


For Querying scalar values I personally prefer session.createSQLQuery
Quote:
what does it mean setCacheable on the query?


It puts the result into Second Level cache if you properly configure the Second Level cache.
Second Level cache is optional and may increase the performance of your application.

Quote:
when can i flush this cacheable?


What do you mean with 'flushing the cacheable' ?
Do you mean evict?


Top
 Profile  
 
 Post subject: Re: Understanding how to use complicated queries
PostPosted: Mon Feb 22, 2010 12:45 pm 
Beginner
Beginner

Joined: Sun Jan 24, 2010 3:04 am
Posts: 20
Thanks
I mean by flush - that if this query was saved using cacheable true, how can i not cache it - let's say when i know that new data was inserted to the database and may influence this query?


Top
 Profile  
 
 Post subject: Re: Understanding how to use complicated queries
PostPosted: Wed Feb 24, 2010 6:14 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
how can i not cache it - let's say when i know that new data was inserted to the database and may influence this query?


You need no worry about, it's hibernate itself checking if a cached query-result-set is still valid.
For this purpose (if hibernate.cache.use_query_cache is enabled) hibernate maintains the UpdateTimeStampsRegion
where it keeps track whenever data was inserted -update -deleted on the database.


Top
 Profile  
 
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.