-->
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: criteria order for joined table property?
PostPosted: Mon Apr 14, 2008 1:24 pm 
Newbie

Joined: Mon Apr 14, 2008 1:13 pm
Posts: 11
This is undoubtedly something stupid on my part and I'm sure this must have been asked before but I can't find the answer... so here goes:

I have two entities, Person and Country. There is a many to one relationship from Person to Country (i.e. a person has a country).

I want to get a list of people sorted by the name of their country.

But with the following criteria I get org.hibernate.QueryException: could not resolve property: country.name

Criteria criteria = session.createCriteria(Person.class);
criteria.addOrder(Order.asc("country.name"));
criteria.list();

Country does indeed have a publicly accessible name property and if remove the addOrder line I can get the country name on objects returned in the list as expected (by calling person.getCountry().getName())

What am I missing?


Top
 Profile  
 
 Post subject: re: criteria order for joined table property?
PostPosted: Mon Apr 14, 2008 1:31 pm 
Newbie

Joined: Mon Apr 14, 2008 1:13 pm
Posts: 11
To answer my own question, the correct code looks like this:

Criteria criteria = session.createCriteria(Person.class);
criteria.createCriteria("country").addOrder(Order.asc("name"));
criteria.list();


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.