-->
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.  [ 5 posts ] 
Author Message
 Post subject: 2X more joins that are needed
PostPosted: Thu Nov 03, 2005 1:43 pm 
Newbie

Joined: Thu Nov 03, 2005 1:31 pm
Posts: 2
A many-to-many uses a join table in the middle that just contains pairs of IDs. When I reach across the many-to-many just to get IDs I expect hibernate to get them from the join-table but, wastefully, it doesn't. Example SQL below.


Hibernate version:

hibernate-3.0.3.tar.gz

Name and version of the database you are using:

mysql Ver 12.22 Distrib 4.0.23, for pc-linux-gnu (i386)

The generated SQL (show_sql=true):

something like this
Code:
select count(*) from Left l inner join JoinTable j on l.id=j.left_id inner join Right r on j.right_id=r.id where r.id=11;


when SQL like this (one join less) would have done just as well:
Code:
select count(*) from Left l inner join JoinTable j on l.id=j.left_id where j.right_id=11;


(you see there is no need to go further than the JoinTable as that knows all there is to know about the IDs on its right)

Is this a known issue?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 2:53 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Depending on your configuration hibernate may do some eager (pre) fetching. Check
  • your mapping files. Did you set Right class to lazy=false
  • your cfg.xml file. Set hibernate.max_fetch_depth=0 if you don't want to have any eager fetching.


HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 8:42 am 
Newbie

Joined: Thu Nov 03, 2005 1:31 pm
Posts: 2
setting lazy=false seems unlikely to give me more laziness

also the current inefficent query is not a kind of eagerness because Hibernate gains no additional information through doing the extra table join

it's only a waste of CPU so I'm suprised Hibernate does it under any circumstances

if I have time I'll try and boil down a self-contained test case


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 8:52 am 
Beginner
Beginner

Joined: Mon Oct 24, 2005 9:46 am
Posts: 22
Location: Germany
whats your hql?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 4:02 pm 
Regular
Regular

Joined: Sat Nov 19, 2005 2:46 pm
Posts: 69
dhatomic: he asked if you *had* set lazy=false; he didn't ask you *to* set lazy=false

I have many-to-many mappings in my current app, and I want entire objects, not just the id values, so hibernate is doing the right thing for me. I can't see the value in retrieving only id values, unless you're going to use them to load the objects themselves....

_________________
Stewart
London, UK


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