-->
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: addAll vs Hibernate.initialize: bug or cool feature
PostPosted: Thu Dec 29, 2011 7:55 am 
Newbie

Joined: Tue Dec 27, 2011 1:33 pm
Posts: 4
I need to provide explanation why following code works well:

List<Child> dummyList = new ArrayList<Child>();
for(Parent parent : parents) {
dummyList .addAll(parent.getChildren());
}

'Parent'-'Children' is mapped as

<bag name="children" cascade="all" batch-size="50" fetch="select">
<key column="PARENT_ID" foreign-key="FK_FFP_METADATA_FFP" />
<one-to-many class="Child" />
</bag>
-------
In DAO layer, when line 'dummyList .addAll(parent.getChildren());' is executed, children collections for ALL parents are loaded (initialized). This is exactly what I want.
=======================================
If, instead of 'addAll' I put following line:
Hibernate.initialize(parent.getChildren());
there will be initialized children collection for single (current) parrent only. That is behavior I can expect.

Can someone explain why, in first case, 'children' collections are initialized for all 'parents' and not just current 'parent'?


Last edited by bjevta on Thu Dec 29, 2011 9:28 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: addAll vs Hibernate.initialize: bug or cool feature
PostPosted: Thu Dec 29, 2011 9:02 am 
Regular
Regular

Joined: Wed Jan 11, 2006 12:49 pm
Posts: 64
Location: Campinas, Brazil
I would guess there is some eager-loading taking place somewhere, but without a more complete mapping it is hard to tell.

_________________
Henrique Sousa
Don't forget to rate useful responses


Top
 Profile  
 
 Post subject: Re: addAll vs Hibernate.initialize: bug or cool feature
PostPosted: Thu Dec 29, 2011 11:43 am 
Newbie

Joined: Tue Dec 27, 2011 1:33 pm
Posts: 4
there is not much mapping. simple parent-child relationship, bag on many side.

anybody else? at least idea where to look for.


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.