-->
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.  [ 2 posts ] 
Author Message
 Post subject: Sort and limit in HQL
PostPosted: Fri Nov 11, 2005 7:41 am 
Newbie

Joined: Fri Nov 11, 2005 7:22 am
Posts: 1
How can I limit the number of results AFTER sorting using HQL (and Oracle)?

This query:

FROM mytable WHERE startdate >= :start AND ROWNUM <= :maxResults ORDER BY lastname DESC

limit results BEFORE sorting.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 11, 2005 7:41 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Your results can be treated as a plain .NET collection. Just remember that NH knows everything inside the collection it gave you. This should give you a new collection.
Code:
IList results = mySession.Find(......);
ArrayList myResult = results.GetRange( StartRowNum, MaxResults );
return myResult;
This will disable some of the smart things NH does with collections, though. For example, you can't do
Code:
myResult.Remove(3);
mySession.Flush();
and expect NH to remove the item with ID=3. Only the "results" collection returned from the mySession.Find above would be able to do that.


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