-->
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: no result for left join with empty set
PostPosted: Thu Mar 30, 2006 4:49 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3

Hibernate Query:
select count(q), count(b)
from Quote q left join q.BookingSet b where q.CreateDate =?

Count(q) doesnt include quotes that there is no booking for them. So
then what is the purpose of left join?? but in mysql it brings back correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 11:58 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Try that query without the count(b). I think it's that that's ruining things for you. It's essentially adding in the requirement that b is not null, nullifying the effect of the left join. You may be able to get what you want with this query:
Code:
select count(q), count(q.BookingSet.id)
from Quote q where q.CreateDate =?
That exploits the fact that <association>.id is not joined, it uses the foreign key value in the base table. I'm not sure that that'll work: if it doesn't, you may have to go with the cross-join:
Code:
select count(q), count(b)
from Quote q, BookingSet b
where q.CreateDate =?
  and (q.BookingSet is empty or q.BookingSet = b)


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.