-->
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.  [ 1 post ] 
Author Message
 Post subject: difference in query parsing from 2.x
PostPosted: Fri Mar 25, 2005 1:39 pm 
Newbie

Joined: Fri Mar 25, 2005 1:16 pm
Posts: 13
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)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.