-->
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: query order by an empty field doesn't return every rows
PostPosted: Fri Mar 05, 2010 8:40 am 
Newbie

Joined: Thu Feb 18, 2010 6:11 am
Posts: 5
Hi, I have a query like this
select t from Orders t order by t.merchanType.varMercTypeDescription desc
The problem I have is if the field merchanType is empty, the query doesn't return that row. I have a grid where I want to let the user order by field. The other fields are always filled so it works great with them but when I order by this merchaType field it just returns those not empty. Anyone knows how can I resolve this?
Thank you


Top
 Profile  
 
 Post subject: Re: query order by an empty field doesn't return every rows
PostPosted: Fri Mar 05, 2010 9:25 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You'll need to do an explicit left join if you want to keep null associations:

Code:
select t from Orders t left join t.merchanType m order by m.varMercTypeDescription desc


The implicit join (dot notation) results in an inner join which excludes null associations.


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.