-->
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.  [ 3 posts ] 
Author Message
 Post subject: Implicit joins with select distinct?
PostPosted: Fri May 10, 2013 8:31 am 
Newbie

Joined: Fri May 10, 2013 8:16 am
Posts: 3
Hello,

We are in the process of upgrading from Hibernate 3.2 to either Hibernate 3.6.10 or 4.x. Unfortunately, HQL queries as the following one:

Code:
select distinct  childTable from  parentTable  order by  parentTable.childTable.description

generate incorrect queries (with both Oracle10gDialect and DB2Dialect) like the following one:

(In Hibernate 3 Oracle10gDialect or DB2Dialect, in hibernate 4 is similar and also incorrect).

Code:
SELECT ...
FROM PARENT_TABLE parentTable0 inner join  CHILD_TABLE childTable1 ON [condition]  ,
CHILD_TABLE childTable2    order by  childTable2.A_DESCRIPTION



Notice this works correctly if we use explicit joins but due to our huge codebase and the dynamic nature of many of our queries this would be an extremely costly task.

Is this a bug in Hibernate 3.5-3.6-4? According to the documentation navigating through deferencing via dot notation should work; is there any in-depth documentation about the cases in which implicit joining works and the cases in which it doesn't? I cannot find any documentation or bug report about this behaviour.


Last edited by tatsuyamm on Tue May 21, 2013 4:01 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Implicit joins with select distinct?
PostPosted: Mon May 13, 2013 4:41 am 
Newbie

Joined: Fri May 10, 2013 8:16 am
Posts: 3
BTW, If you think I'm just being stupid, tell me :)


Top
 Profile  
 
 Post subject: Re: Implicit joins with select distinct?
PostPosted: Tue May 21, 2013 4:11 am 
Newbie

Joined: Fri May 10, 2013 8:16 am
Posts: 3
I don't know if my original question was clear enough. The problem is that , when using "SELECT DISTINCT ChildObject from ParentObject " ordering by a field of the ChildObject without an explicit Join (ORDER BY ParentObject.ChildObject.Description ) , the SQL query that Hibernate builds has two INNER JOINS to the second table, or an INNER JOIN + a cartesian product including the second table.

select ... from PARENT_TABLE parent inner join CHILD_TABLE1 child1 on parent.ID_CHILD =child1.ID_CHILD inner join CHILD_TABLE2 child2 on parent.ID_CHILD =child2.ID_CHILD (Hibernate 4)
select ... from PARENT_TABLE parent inner join CHILD_TABLE1 child1 on parent.ID_CHILD =child1.ID_CHILD , CHILD_TABLE2 child2 where parent.ID_CHILD =child2.ID_CHILD (Hibernate 3.5+)

This works seamlessly if we use an explicit join in SQL rather than using parent.child.Description. Is this a problem in our query ? It used to work in Hibernate 3.2 .


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