-->
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: LazyInitializationException accessing Id property on proxy
PostPosted: Fri May 09, 2008 6:00 am 
Newbie

Joined: Thu Aug 17, 2006 7:25 am
Posts: 7
We have a parent object with a lazily loaded child (mapped as many-to-one). When we try to access the child's Id property after the Session in which we retrieve the parent has been closed, a LazyInitializationException is thrown... but this seems to contradict the behaviour described in 14.2 of the nHib 1.0.2 documentation ( we are using v1.2 but I assume this it is still true that you should be able to access the ID of a proxy without a database call being required ).

Our mapping file is as follows:

Code:
<class name="Parent" proxy="IParent" table="parent">

<id name="Id" type="System.Decimal" unsaved-value="0" column="ParentId" >

<generator class="native"/>

</id>

<version name="Version" type="Int32" column="ccn" unsaved-value="-1"/>

<snipped>

<many-to-one name="Child" column="ChildId" class="Child"/>

</class>

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 6:55 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post the Child mapping ? Maybe you have the same problem mentioned here http://forum.hibernate.org/viewtopic.php?t=986520. Also make sure, that your debugger does not access any of the properties of child (Locals and Auto window).

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 09, 2008 7:17 am 
Newbie

Joined: Thu Aug 17, 2006 7:25 am
Posts: 7
Actually, in this case the child object is that same as the parent object (i.e. it is a self-join).

For further info, the identifier is mapped as access="property".

I can confirm that this is not the debugger that is causing this as it is occurring in our production environment (which doesn't even have Studio installed)

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 1:34 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
What happens if you execute the same code with the session still opened ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 19, 2008 6:55 am 
Newbie

Joined: Thu Aug 17, 2006 7:25 am
Posts: 7
When the session is still open it all works fine. I assume it is going back to the database though.

I have been doing a lot of work on this in the last week or so and have been meaning to post my findings back here for others to benefit.

I have tracked the problem down to some base classes and interfaces in our data access framework we have built around NHibernate.

I built a debug version of NH to allow me to step into the code and found that the problem was occurring in the Invoke method of the LazyInitializer object at the part where it checks whether the property that was called by the client code is the same as the get identifier method, which is populated when the persister was setup.

Further investigation has found that it is to do with the persistent class implementing an interface with a generic parameter on it as when generics are removed it all works fine.

The problem was also only affecting some of the PC's in the office. This is because some have SP1 of the .NET framework installed and some don't. It works with generics on SP1.

Hope this helps.


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.