-->
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.  [ 1 post ] 
Author Message
 Post subject: Sorting by field in associated obj without losing null vals
PostPosted: Fri Sep 22, 2006 11:34 am 
Newbie

Joined: Fri Sep 22, 2006 11:04 am
Posts: 1
Location: Chicago, IL
I'm using the Criteria api to request a collection (organizations) and sort it by a value (state_name) in an associated object (state). The state is related to the organization by a nullable column in the organization table (state_id).

The sort works well, except that it discards all organizations that have a null state_id. Is there a way to sort by state.state_name while retaining all organizations that don't have a state?

I'm not married to the Criteria api, but would prefer to use it if possible.

Here's what I'm doing:
Code:
Criteria orgCriteria = session.createCriteria(Organization.class);

// Select a collection of organizations based on organization name
orgCriteria.add(Restrictions.like("name",("%" + OrganizationName + "%")));

// Sort organizations by state_name
Criteria stateCriteria = orgCriteria.createCriteria("state");
stateCriteria.addOrder(Order.asc("state_name"));

theseOrgs = orgCriteria.list();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.