-->
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 related object field
PostPosted: Thu Jan 28, 2010 8:53 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
My dao supports paging and sorting:

criteria.setFirstResult(firstRow);
criteria.setMaxResults(rowCount);
criteria.addOrder(sortAscending ? Order.desc(sortField) : Order.asc(sortField));

The object that I have has a one-to-many relationship and I'd like to support sorting on one of those columns. What sortField do I pass?


Top
 Profile  
 
 Post subject: Re: Order By related object field
PostPosted: Thu Jan 28, 2010 9:08 am 
Beginner
Beginner

Joined: Fri Jul 20, 2007 10:38 am
Posts: 49
I don't know if this is a common solution, but I think this one works:
I added a createAlias to the related object so I can pass a field like "related.fieldName"


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.