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: when should i use one-to-many fetch="join"
PostPosted: Sun Mar 30, 2008 7:13 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
why is it that only one collection per class can have a fetch="join" on a one-to-many? how do you know when to use fetch="join" instead of fetch="select" ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 24, 2008 9:10 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
the java persistance with hibernate book states:
Quote:
"Every time I need an Item, I also need the
seller of that Item.”
If you can make that statement, you should go into your
mapping metadata, enable eager fetching for the seller association, and utilize SQL joins:


Code:
<class name="Item" table="ITEM">
...
<many-to-one name="seller"
class="User"
column="SELLER_ID"
update="false"
fetch="join"/>
</class>




do i need to "enable eager fetching" or does setting fetch="join" implicitly enable eager fetching?

but i still don't know if only one collection per class is allowed to have fetch="join" ? i read that is does in Hibernate Quickly by Peak Heudecker, but that book is a couple years old so....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 2:14 pm 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
bump


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 15, 2008 4:05 am 
Beginner
Beginner

Joined: Wed Mar 19, 2008 12:10 am
Posts: 36
any1?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 16, 2008 5:24 pm 
Newbie

Joined: Thu Mar 27, 2008 10:50 am
Posts: 13
1. Yes, fetch="join" disables lazy loading. i.e. enables eager loading. The said book says so right after the excerpt you have quoted. But there is a way to eagerly fetch without using fetch="join". You could eagerly fetch using separate selects instead of joins in the same (one) select by using fetch="select" together with lazy="false".
The best way to think about it is: 'fetch="bla" basically specifies how to perform the (eager) fetch.

2. The thing about eagerly fetching multiple collections using fetch="join" is that it could lead to the performance problems due to many joins in the same query and the implied amount of work Hibernate has to do to marshal the resultset into persistent objects and collections. You might want to read section 13.2.5 in detail. Specifically the subsection titled 'The Cartesian product problem'.


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.