-->
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: Possible to add "order by" to the named query?
PostPosted: Sat Apr 19, 2008 1:41 pm 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
Hi,

I need to add an "order by" clause to the named query so the question is whether it is possible at all and how to if yes. What I would like to achieve is to add optionally ordering of the result of the original query:

Code:
IQuery q = sess.GetNamedQuery(...);

// here we set parameters to the query...

if(paging)
{
  q.SetFirstResult(...);
  q.SetMaxResults(...);
}

if(applyOrder)
{
  // here to add order by stuff to the query?
}

q.List();


This seems to be quite typical scenario for DAO implementations and in case of criteria it is quite easy to do... but I need (for now) it for case of HQL queries.

TIA

_________________
Please rate this post if you've found it helpfull
Roland


Top
 Profile  
 
 Post subject: Possible to add "order by" to the named query?
PostPosted: Sun Apr 20, 2008 7:21 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi TIA,

I think that's only possible if you're using the ICriteria API, but not for IQuery.

Regards,
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 21, 2008 1:50 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
I am also starting thinking so - the only way I've found (except of manually assembled query) is to manipulate the query text by adding an "order by" clause. But this method I would like to avoid because it is error prone - what if the clause is there already? what if adding the clause brakes the syntax?

_________________
Please rate this post if you've found it helpfull
Roland


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.