-->
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.  [ 4 posts ] 
Author Message
 Post subject: Order by bug
PostPosted: Sun Sep 11, 2005 10:47 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
I believe I have found a bug when ordering by a property of a property.
I am not sure where to post bugs so I will do it here until I get directed to otherwise.

I have one class with a relationship to another enitity. Retrieving a list of objects works fine. But when I sort by a property of the related class I get weird results. The query fails to return objects where the related entity is null.

here is the query:
Code:
from JobPost as post  where post.Department = ? order by post.StaffMember.LastName ASC


here is the resulting sql from the query:
Code:
select top 10 jobpost0_.jobpostid as jobpostid, jobpost0_.memberid as memberid, jobpost0_.departmentid as departme4_ from jobpost jobpost0_, member member1_ where jobpost0_.memberid=member1_.memberid and ((jobpost0_.departmentid=@p0)) order by  member1_.LastName ASC', N'@p0 int', @p0 = 1


The code creating the query has wrongfuly added this jobpost0_.memberid=member1_.memberid. The member can be null so incorrect results are produced. I believe a join should be created in this instance.

Let me know if I should post this somewhere else or if you need any more info.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 3:52 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Quote:
I believe a join should be created in this instance.


Well, you do get a join, but it's an inner join. If you want to get a left join, you need to alter the query to specify it explicitly:
Code:
select post from JobPost as post left join post.StaffMember member where post.Department = ? order by member.LastName ASC


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 4:11 am 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
yes but since its an assosciation, isnt it assumed that it should be an outer join. Im not filtering on the assosciation, just sorting.

Seems like an unexpected result to me.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 4:35 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
HQL is a hybrid between objects and SQL, so some results might be unexpected. As in SQL, the default in HQL are inner joins.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.