-->
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: Order By using Criteria API
PostPosted: Thu Sep 29, 2005 4:45 am 
Newbie

Joined: Thu Aug 18, 2005 4:23 am
Posts: 11
Location: Sheffield
Is there anyway of reproducing the following SQL using the Criteria API?

SELECT *
FROM Table tbl
ORDER BY (value1 * value2)

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 9:12 am 
Beginner
Beginner

Joined: Tue Sep 06, 2005 5:16 pm
Posts: 24
Location: USA
Use the following code


Code:
List cats = sess.createCriteria(Cat.class)
    .add( Expression.like("name", "F%")
    .addOrder( Order.asc("name") )
    .addOrder( Order.desc("age") )
    .setMaxResults(50)
    .list();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 9:33 am 
Newbie

Joined: Thu Aug 18, 2005 4:23 am
Posts: 11
Location: Sheffield
its a bit more complicated than that. its my fault for showing to simplified code.

What I want to do is order by the results by the product of values from 2 or more tables other than the start table. The obvious thing is to have a derived field but Im really put off by how often the SQL within the derived field is run, which will likely give me performance issues (especially since it will contain select statements to multiple tables).


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.