I had a query like this that worked in 2.1.6:
Code:
select distinct child.parent from Child child
where child.readyToGo = 1 and child.parent.readyToGo = 1
order by child.parent.orderMe
Which generated SQL like this:
Code:
SELECT DISTINCT parent1.*
FROM child child0, parent parent1
WHERE child0.readyToGo = 1 and parent1.readyToGo = 1 and child0.parent_id = parent1.id
ORDER BY parent1.orderMe
However, in 3.0rc1 the generated erroneous SQL is like this:
Code:
SELECT DISTINCT parent2.*
FROM child child0, parent parent1, parent parent2
WHERE child0.readyToGo = 1 and parent1.readyToGo = 1 and child0.parent_id = parent1.id and child0.parent_id = parent2.id
ORDER BY parent2.orderMe
The fix is this HQL:
Code:
select distinct p from Child child join child.parent p
where child.readyToGo = 1 and p.readyToGo = 1
order by p.orderMe
It seems like I've had this problem on similary queries in 2.x, but obviously not this one. However, the syntax seems intuitive to me, as the hibernate mapping already knows about the joins and relationships. This makes the HQL very more Java property-path like, instead of more SQL like. (OJB works like this.)
Was there a reason this changed? I suspect it's just an unknown consequence of the new parser. I can see why the fix version works, but supporing a path-like notation abstracts the HQL away from the SQL even more. It seems by default that you'd only want one join, unless you knew what you were doing and specifically joined twice. (Speaking of that, according to this bug, the criteria API CAN'T do that at all:
http://forum.hibernate.org/viewtopic.php?t=931249&highlight=double+join)