-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate.initialize() ignores lazy?
PostPosted: Wed Dec 10, 2008 7:46 am 
Newbie

Joined: Wed Dec 10, 2008 6:35 am
Posts: 1
Hibernate version: 3.2

Basically I have a class containing a collection of a class that contains another collection. All mappings for collections are set to be lazy.

Stripped down mapping:

Code:
<class name="TheClass">
      
   <set name="collection1" lazy="true">
      <one-to-many class="OtherClass"/>
   </set>
</class>

<class name="OtherClass">

   <list name="collection2" lazy="true">
      <many-to-many class="YetAnotherClass"/>
   </list>
</class>


First retrieve theClass:
Code:
TheClass theClass = theClassDAO.getTheClass(id);


Since I'm using lazy, collection1 hasn't been loaded. Fine, now I want to load collection1:

Code:
Hibernate.initialize(theClass.getCollection1);


Hibernate will now also load collection2 even though it's tagged as lazy. Is this the default behaviour for Hibernate.initialize()? The entire tree will be loaded?

I had expected only collection1 to be loaded. Much obliged for any comments.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 12:25 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
I think something might be off in how you're testing this as I wrote a test myself yesterday and it worked how I had expected it to. i.e. only the first level was initialized and when I tried to access the 2nd level after the session was closed it blew the lazy initialization exception.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


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