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.  [ 11 posts ] 
Author Message
 Post subject: Lazy initialization accross multiple sessions
PostPosted: Tue Dec 30, 2003 2:56 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
I have a graph with many levels of parent-children. I modeled this graph with lazy initialization. I need to load the top part of this graph in one session, modify it when necessary, and if needed load other sets of children in new subsequent sessions. At the end I cascade-update the whole graph.

Hibernate documentation specifies:
"The lock() method allows the application to reassociate an unmodified object with a new session." section 8.6.

Gavin said:
"For unmodified objects: session.lock(o, LockMode.NONE)
For modified objects: session.update(o)" in this thread:
http://forum.hibernate.org/viewtopic.php?t=926239&highlight=


I don't want to persist the changes to the loaded part until I am done (not just to lazy initialize a collection).
I was able to load children of a modified parent, without losing the changes to the parent with the following code:

session.lock(parent, LockMode.NONE);
if(!Hibernate.isInitialized(parent.getChildren())){
Hibernate.initialize(parent.getChildren());
}

What am I missing?

mota


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 3:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Ahem, what is your problem? What exactly is not working?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 3:21 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
I am locking (associating with a new session) a modified persistent object, and it is working. This is not supposed to work. Am I missing something?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 3:34 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Why should this not work. I think this is supported for a short time though, since 2.1 ? dont know exactly


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 3:57 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
Gavin said on December 10, 2003:
"For unmodified objects: session.lock(o, LockMode.NONE)
For modified objects: session.update(o)" in this thread:
http://forum.hibernate.org/viewtopic.ph ... highlight=


And I am using a Hibernate jar downloaded on November 29.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 4:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Gavin said it works, it does work for you, I dont get where your problem is.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 4:38 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
Gavin said, for modified objects, we should use session.update() and not session.lock(). I am using *session.lock() for modified objects*


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 4:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
That just means your modifications will not be stored. You need to use session.update() for that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 5:08 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
If I can ask the question in different wording:
What does "session2.lock(o, LockMode.NONE)" do, when object o is loaded by session1 and modified after session1 is closed? session2 being the new session.

Is this supposed to just reassociate the modified object (as is) with the new session?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 5:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Exactly


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 5:34 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
That makes sense.

Thank you.


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