-->
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: Howto execute a subquery which contains OFFSET and LIMIT?
PostPosted: Tue Aug 17, 2010 9:52 am 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hello,

What I would like to do is something like:
Code:
session.createQuery("FROM Entry e LEFT JOIN e.pilot WHERE e.id IN (SELECT e.id FROM Entry e OFFSET 100 LIMIT 10 ORDER BY e.id ASC)");

However Hibernate struggles with the OFFSET-Keyword. Is there anything I can do to make it tolerate it?
If possible I would prefer not to use createSQLQuery.

I also had a look at the Criteria-API which I prefer, however DetachedCriteria lacks the Methods setFirstResults() and setMaxResults() which I would require :(

Thank you in advance, Clemens


Top
 Profile  
 
 Post subject: Re: Howto execute a subquery which contains OFFSET and LIMIT?
PostPosted: Tue Aug 17, 2010 10:23 am 
Newbie

Joined: Mon Aug 16, 2010 12:32 pm
Posts: 12
try those 2 methods, it's the only way i think

Code:
         qry.setMaxResults(maxResults);
         qry.setFirstResult(offset);


Top
 Profile  
 
 Post subject: Re: Howto execute a subquery which contains OFFSET and LIMIT?
PostPosted: Tue Aug 17, 2010 10:43 am 
Beginner
Beginner

Joined: Tue Jul 03, 2007 8:47 am
Posts: 46
Hi Martin,

The Problem with using setFirstResult()/setMaxResult() on the Query directly is performance, because at least in my case PostgreSQL does JOIN all rows, not only the rows between OFFSET and LIMIT even if it would be possible to do so, because the columns joined in don't affect the ordering.

Is there some way to escape SQL keywords not known to Hibernate, so that it doesn't complain executing HQL queries it doesn't fully "understand"?

Thank you in advance, Clemens


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.