-->
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 results on property of associated entity
PostPosted: Tue May 09, 2006 4:47 pm 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:18 am
Posts: 28
Hibernate version:
3.1.2

Hi.
I've been reading about the Criteria API but can't quite figure out how to order results on a property of an associated entity. I want something like this:

Code:
Criteria criteria = session.createCriteria(User.class);
criteria.addOrder(Order.asc("category.name"));


("category" is a many-to-one association)
This results in a QueryException "could not resolve property: category.name". I tried to add Fetchmode.EAGER for the "category" property but that didn't make any difference. Help?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 4:57 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Code:
Criteria criteria = session.createCriteria(User.class);
criteria.createAlias( "category", "catg" );
criteria.addOrder( Order.asc("catg.name") );


This worked fine for me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 5:37 pm 
Beginner
Beginner

Joined: Wed Jan 25, 2006 10:18 am
Posts: 28
Thanks, that works great.


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.