Thanks for your reply,
Your right there is no join just a cross select in the example. I thought that hibernate generates a join when i join a object with his collection like "meeting" and "deadline" because the necessary where part of the join clause is whitin the hibernate mapping.
Sorry for this. However even if i modify the example like this:
Code:
select
m
from
Meeting m
where
m.id in (
select
m.id
from
Meeting m
left outer join
m.deadlines d
where
m.id = d.meeting.id
group by
m.id
having
max(d.deadline) < :rightNow or
max(d.deadline) = null
)
hibernates generates somthing like this:
Code:
select
*
from
HB_MEETING meeting0_
where
meeting0_.ID in (
select
meeting1_.ID
from
HB_MEETING meeting1_, HB_DEADLINE deadlines2_
where
meeting1_.ID=deadlines2_.MEETING_ID
group by
meeting1_.ID
having
max(deadlines2_.DEADLINE)<? or
max(deadlines2_.DEADLINE) is null
)
)
and thats not what i want. I need a "left join" whitin the subselect not an "inner join" because in this way all meetings that have no deadlines will not be part of the result.
When i excecute the subselect not as subselect but just as a select like:
Code:
select
m.id
from
Meeting m
left outer join
m.deadlines d
where
m.id = d.meeting.id
group by
m.id
having
max(d.deadline) < :rightNow or
max(d.deadline) = null
hibernates generates:
Code:
select
meeting0_.ID as col_0_0_
from
HB_MEETING meeting0_
left outer join
HB_DEADLINE deadlines1_
on
meeting0_.ID=deadlines1_.MEETING_ID
where
meeting0_.ID=deadlines1_.MEETING_ID
group by
meeting0_.ID
having
max(deadlines1_.DEADLINE)<? or
max(deadlines1_.DEADLINE) is null
Now i got my "left outer join" and by the ways it seems like its needless to specify a where clause like "meeting0_.ID=deadlines1_.MEETING_ID" in hql.
So where is my mistake? Wy depends the generated SQL of the position of a select. Should not be the generated SQL always be the same regardless if its a subselect or not?
Thanks for your help.
Regards Sebastian.