-->
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.  [ 5 posts ] 
Author Message
 Post subject: Lazy NON-CASCADED Properties after re-attachment
PostPosted: Thu Oct 05, 2006 7:35 pm 
Beginner
Beginner

Joined: Wed Jul 05, 2006 12:45 pm
Posts: 21
Hibernate version:
1.2.0 beta 1

I am getting LazyInitializationException errors under the following combination of conditions:
- I am accessing an uninitialized proxy
- this proxy represents a property which is set to cascade="none"
- the root entity was detached, and then re-attached using Lock()

In stepping through the code, it seems that Lock() successfully reattaches the root entity, and cascades down through the object graph for all properties which are... well, set to CASCADE :-p

However, this means that any non-cascaded properties, which have uninitialized proxies, will not be associated with the new active session, and thus will not be usable (throwing the above exception).

I understand this behaviour - after all, if we made changes to these non-cascaded properties, and flushed the session, we would inadvertanly write the changes to the database, against the cascading rules specified.

But how does one sovle this problem? I have googled for several days with no suggestions found. Please please please don't think this is another "lazy loading after session closed" issue. Though I am new, i think i've done the due diligence in reading documentation, searching, and trying the accepted patters for this kind of thing.

So in closing, can anyone confirm this behaviour, and has anyone come up with a solution... (i.e. "you HAVE to initialize lazy non-cascaded properties")?

Thank you so much for reading this far, and any help you may offer.


Full stack trace of any exception that occurs:
Could not initialize proxy - the owning Session was closed.

at NHibernate.Proxy.LazyInitializer.Initialize() in C:\Development\cpbinc\NHibernate-1.2.0.beta1\nhibernate\src\NHibernate\Proxy\LazyInitializer.cs:line 81
at NHibernate.Proxy.LazyInitializer.GetImplementation() in C:\Development\cpbinc\NHibernate-1.2.0.beta1\nhibernate\src\NHibernate\Proxy\LazyInitializer.cs:line 240
at NHibernate.Proxy.CastleLazyInitializer.Intercept(IInvocation invocation, Object[] args) in C:\Development\cpbinc\NHibernate-1.2.0.beta1\nhibernate\src\NHibernate\Proxy\CastleLazyInitializer.cs:line 59
at CProxyTypeAddresscommon_INHibernateProxy_ISerializable2.Equals(Object obj)
at DFWHC.GroupOne.GoRes.business.common.applicant.ApplicantAddress.Equals(Object obj) in C:\Development\dfw_hospital\GroupOne\GoRes\library\business\common\applicant\ApplicantAddress.cs:line 34
at DFWHC.GroupOne.GoRes.business.common.applicant.ApplicantAddress.get_IsPrimary() in C:\Development\dfw_hospital\GroupOne\GoRes\library\business\common\applicant\ApplicantAddress.cs:line 65


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 12:39 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, you have to reattach those objects manually.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 11:07 am 
Beginner
Beginner

Joined: Wed Jul 05, 2006 12:45 pm
Posts: 21
Thanks for replying Sergey.

When re-attaching a detached entity, is there any way to mimic the behaviour observed when an entity is loaded originally (i.e. using session.Get())?

Specifically, where non-cascaded properties are attached, but not checked for dirty status (and thus non persisted) whent he session is flushed?

Thank you,

-Sasha Borodin


Top
 Profile  
 
 Post subject: Re: Lazy NON-CASCADED Properties after re-attachment
PostPosted: Mon Nov 05, 2007 10:47 pm 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
whoissasha wrote:
But how does one sovle this problem?


My rather 'brute force' solution to this problem may not be much of a solution at all. But, if practical, I load the parent object using 'get' (ie instead of Lock) using a new reference. Creating a new, fresh parent object with no old child objects lying around (from a previous peristence context).

Performance might suffer (negligible in my case) but the code is simple and works...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 10:06 pm 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
What are the chances of changing NHibernate to just 'handle' this situation without an exception?

Is it feasible/desirable?

I'm often reconnecting sessions with objects that were retrieved from other sessions. Such that operating on this object works sometimes and not other times, depending on whether you had any proxy's initialised or not (which is pretty much impossible or very difficult to work out beforehand).


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