-->
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: Lazy initialization questions
PostPosted: Thu Nov 06, 2003 12:52 am 
Beginner
Beginner

Joined: Thu Sep 04, 2003 1:46 pm
Posts: 20
Hello,

How does lazy loading of collections work across sessions?

I have an object that I load in one session using session.find(....);

It has several collections that are defined with the lazy="true" attribute.

In another transaction, I want to be able to access certain (but not all) of the lazy collections.

I do the following:

// open the session
session.save(myObject); // this appears to lazy-initialize all the collections!

myObject.getACollection();


if I don't do session.save or load or update, then I get an exception that says it failed to lazy initialize the collection - no session.

If I do a session.save, load, or update, then it intializes all the lazy collections.

Is this the way it is meant to work? It seems the only way a lazy collection works is if you find the object within the same session as the one you access the collections within.

Thanks in advance,
-Ben


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 06, 2003 1:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Lazy loading only working from with a session. The easiest is using the same session otherwise you have to re-associate the object with the new session. Re-associate using session.update() or (2.1) session.lock(). The final option is to disconnect the session and the reconnect it later (for example you may have stored it in a HTTP session).


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.