-->
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: Join versus fetch join
PostPosted: Tue Dec 09, 2003 2:07 pm 
Newbie

Joined: Tue Dec 09, 2003 1:59 pm
Posts: 5
Hello everyone,

We're trying to determine by HQL when a lazy collection will be join-loaded. We're using fetch join but we get what it seems a strange result.

This HQL query works well:
select distinct d from DescripcioAssignatura d join d.fontsInformacio
(in fact, kinda "select distinct p from parent p join p.children")
It results in 4 rows, but it doesn't load the lazy collection children. That's ok.

This HQL query...:
select distinct d from DescripcioAssignatura d join fetch d.fontsInformacio
(in fact, kinda "select distinct p from parent p join fetch p.children")
It results in 20 rows, where each original row is repeated as many times as children it has.

Is this a bug or am I missing something here?

P.S. The collection fontsInformacio (childre) is mapped as follows:

<set name="fontsInformacio" lazy="true" inverse="true" >
<key column="descripcioAssignaturaId"/>
<one-to-many class="es.castinfo.ub.domain.FontInformacio"/>
</set>

Thanks in advance,

Jordi Pradel & Jos


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 3:01 pm 
Newbie

Joined: Fri Sep 19, 2003 1:19 pm
Posts: 18
This is a known issue - HIB-123

As I recall, the last recommended work around was to insert your resultset into a map.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 3:16 pm 
Newbie

Joined: Fri Sep 19, 2003 1:19 pm
Posts: 18
Also, turn on your "show_sql" attribute. Then you can see what Hibernate is doing. In the first scenario, Hibernate is just returning your result set from your main table "DescripcioAssignatura". It is creating proxies for each of your collection associations. When you access your collections, you will see Hibernate generate the appropriate sql to "lazy" load them at that time.

In the second scenario, the "fetch" option is telling Hibernate to "left outer join" your data all at once, no lazy loading. Look at the generated sql. Hibernate is basically passing back to you what it is getting from jdbc. jdbc will return 20 rows due to the joins. Hibernate still loads your collections for you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 09, 2003 7:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I havn't yet decided whether Hibernate should distinctify the query result set automatically. Believe it or not, this can have a significant performance impact, so I lean toward leaving things the way they are and letting the application handle this, if required.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 10, 2003 4:44 am 
Newbie

Joined: Tue Dec 09, 2003 1:59 pm
Posts: 5
gavin wrote:
I havn't yet decided whether Hibernate should distinctify the query result set automatically. Believe it or not, this can have a significant performance impact, so I lean toward leaving things the way they are and letting the application handle this, if required.


Ok, no problem. The application can insert the obtained List in a Set or do any other handling of duplicates.

The only disadvantage then is the difference in semantics between join and fetch join.

P.S. Great forums! Thanks to evaala, gavin and everyone participating in Hibernate forums.

Jordi Pradel


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.