-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL : Implicit and explicit joins
PostPosted: Wed Jan 28, 2004 7:25 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
Hello,

Is it possible to have explanation about the following point. I've got a query in which i have an order by clause that makes HIbernate generate an implicit join on tables.

If I change the query with explicit join, the generated SQL is a little bit different : joins become "inner join" with "on" condition, and performances are better (with the DB I'm using).

Hibernate query (implicit joins)
Code:
select
   m
from
   fr.infologic.superviseur.gestionco.modele.Mouvement m
where
   m.ik in (:listIk)
order by 
   m.cde.heurePrep,
   m.cde.tra.libStd,
   m.cde.livNom,
   m.cdeLig.code


SQL query
Code:
select
   mouvemen0_.ik as ik,
   mouvemen0_.code as code,
   [...]
from
   SV_Mouvement mouvemen0_,
   SV_Commande commande1_,
   SV_Transporteur transpor2_,
   SV_CdeLig cdelig3_
where
   mouvemen0_.noCde=commande1_.ik and
   mouvemen0_.noCde=commande1_.ik and
   commande1_.noTra=transpor2_.ik and
   mouvemen0_.noCdeLig=cdelig3_.ik and
   ((mouvemen0_.ik in(? , ? , ?)))
order by 
   commande1_.heurePrep,
   transpor2_.libStd,
   commande1_.livNom,
   cdelig3_.code



With explicit JOINs


Hibernate Query (explicit joins)
Code:
select
   m
from
   fr.infologic.superviseur.gestionco.modele.Mouvement m
join    
   m.cde.tra
join
   m.cdeLig
where
   m.ik in (:listIk)
order by 
   m.cde.heurePrep,
   m.cde.tra.libStd,
   m.cde.livNom,
   m.cdeLig.code


SQL Query
Code:
select
   mouvemen0_.ik as ik,
   mouvemen0_.code as code,
from
   SV_Mouvement mouvemen0_
inner join
   SV_Commande commande1_
on
   mouvemen0_.noCde=commande1_.ik
inner join
   SV_Transporteur transpor2_
on
   commande1_.noTra=transpor2_.ik
inner join
   SV_CdeLig cdelig3_
on
   mouvemen0_.noCdeLig=cdelig3_.ik
where
   (mouvemen0_.ik in(? , ? , ?))
order by 
   commande1_.heurePrep,
   transpor2_.libStd,
   commande1_.livNom,
   cdelig3_.code



A general way, I'd like to know when Hibernate generates "inner join" with "on" condition and when it uses the syntax with "," and "where" condition.

Thanks

Philippe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
is hibernate.use_outer_join=true ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2004 5:56 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
emmanuel wrote:
is hibernate.use_outer_join=true ?


The line is in comment in hibernate.properties. As we are using SAPDB Dialect, I think it is set to TRUE.

From SAPDB dialect :
getDefaultProperties().setProperty(Environment.USE_OUTER_JOIN, "true");

But isn't the problem is more about the syntax of inner join ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2004 1:29 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually I'm not very familiar with this part of Hibernate

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 2:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
* HQL implicit where-clause joins result in SQL theta-style inner joins
* HQL explicit from-clause joins result in SQL ANSI-style joins


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 9:57 am 
Beginner
Beginner

Joined: Fri Sep 12, 2003 5:13 am
Posts: 22
Thanks for the answer.

Is the "cohabitation" historical, or does it have a special meaning ?

Thanks again

Philippe


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