-->
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: Ordering by two complex, nullable attributes
PostPosted: Thu Sep 18, 2008 8:34 am 
Newbie

Joined: Tue Sep 02, 2008 9:53 am
Posts: 6
I have an entity that has two nullable attributes: a team and a person. Both of them are entities themself and one of them is always null.
Now I'd like to order the entity by the team's and the peron's name combined in one column. But because one of them is null, simply using "order by team.name, person.name" doesn't work.
How can I do that?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 9:29 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
You can create a special, read-only property on the main entity to be sorted, which internally checks for nulls and always returns a composite name or "".

At the HQL level, you can experiment with the coalesce() expression, which returns the first non-null parameter of a parameter list.

_________________
Gonzalo Díaz


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.