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: Order by column from another table?
PostPosted: Tue Jul 18, 2006 9:17 am 
Newbie

Joined: Tue Jul 18, 2006 9:06 am
Posts: 15
Location: .NET
Let's say, I have a class Customer with a property Address.
Address is the class with a property Street.
Customer & Address - two tables in SQL DB.

So, when I get list of Customers:

Code:
ICriteria criteria = session.CreateCriteria(typeof(Customer));


I'd like to order the result (IList) by Address.Street value.

Code:
criteria.AddOrder(Order.Desc("Address.Street"));

is not working, of course.

How can I do it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 10:58 am 
Newbie

Joined: Tue Jul 11, 2006 5:14 am
Posts: 10
Location: Paris, France
That is because de SQL that it generates does not have de column you order by in the select clause

Code:
myCriteria.createCriteria(orderColumn,   JoinFragment.LEFT_OUTER_JOIN);
Order ordre = Order.desc(orderColumn);
myCriteria.addOrder(ordre);


If you are sure that the column by which you order is never null it can be Iner_join, but if there are nulls you'll loose the line

Another problem is if you need distinct, I didn't solve that

I spent quite some time trying to use the criterias with orders and paginations bu it was a pain in the ass and at the end I switched for HQL

Good luck


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.