-->
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.  [ 4 posts ] 
Author Message
 Post subject: Failed to lazily initialize a collection after ISession.Lock
PostPosted: Sat Apr 15, 2006 6:01 pm 
Newbie

Joined: Mon Jan 23, 2006 11:44 pm
Posts: 15
Location: New Jersey, US
Hi,

I am using the Session per HttpRequest pattern in my ASP.NET 2.0 project using NHibernate 1.01.

On one of my pages, I store a loaded object in HttpSession and when the page submits I reassociate it with the CurrentSession in Context by using ISession.Lock(o, LockMode.None) or ISession.Update(o). Then, when I try to access a collection of the object I get the lazy loading error.

If I touch the collection during the loading of the object. No such error pops up.

Do I have to touch all collections in the loading session to make them accessable in the reassoicated session?

Thanks

Hongze


Top
 Profile  
 
 Post subject: I found the cause but not reason.
PostPosted: Sun Apr 16, 2006 9:40 pm 
Newbie

Joined: Mon Jan 23, 2006 11:44 pm
Posts: 15
Location: New Jersey, US
Hi,

I finally resolve the problem. The class relationship is as following:

A references B with many-to-one relationship;
B references C with a set lazily loaded.

When I use None cascading mapping for A referencing B, the error pops up if I try to access a.B.Cs in a reassociated session for a. If save-update cascade value is used, the lazy access works fine.

Can anybody explain this for me?

Thanks,

Hongze


Top
 Profile  
 
 Post subject: What does cascade value play in lazy loading?
PostPosted: Mon Apr 17, 2006 10:22 am 
Newbie

Joined: Mon Jan 23, 2006 11:44 pm
Posts: 15
Location: New Jersey, US
After fixing the problem in my project, I tried some tests. I found if there are any references(many-to-one) on the path to a lazily loaded set, the loading will fail in a ressociated session:

Code:
[Test]
public void LazyLoadingInReassociatedEntity()
{
    ClassA  a = null;
   using (ISession session1 = nhManager.Factory.OpenSession())
   {
   a = (ClassA)session1.Load(typeof(ClassA), 123);
   }

   using (ISession session2 = nhManager.Factory.OpenSession())
   {
      session2.Lock(a, LockMode.None);
      Assert.IsTrue( (a.B.CSet.Length > 0, "CSet should not be empty.");
   }
}
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 18, 2006 12:20 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
This behavior occurs because when you call Lock on A, A.B does not get locked automatically (unless its cascade is set to save-update, as far as I remember). You have to call Lock on A.B for lazy loading of B.CSet to work.


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