The null reference exception is on this line:

// oops, this should have been this instead of base, don't think it
matters
//
int myPropertyValue = this.MyProperty()

In the constructor, "this" is actually a proxy to ChildClass and not
an actual instance of ChildClass.  And when I try to reference the
property on the proxy object that actually exists on the ParentClass,
it throws a null reference exception.

The call stack is pretty deep in the NHibernate code...

[HibernateException: Creating a proxy instance failed]
   NHibernate.ByteCode.Castle.ProxyFactory.GetProxy(Object id,
ISessionImplementor session) in C:\SourceCode\shamu\vendor\NHibernate
\2.1.0.GA\src\NHibernate.ByteCode.Castle\ProxyFactory.cs:43
   NHibernate.Tuple.Entity.AbstractEntityTuplizer.CreateProxy(Object
id, ISessionImplementor session) in C:\SourceCode\shamu\vendor
\NHibernate\2.1.0.GA\src\NHibernate\Tuple\Entity
\AbstractEntityTuplizer.cs:236
   NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy
(Object id, ISessionImplementor session) in C:\SourceCode\shamu\vendor
\NHibernate\2.1.0.GA\src\NHibernate\Persister\Entity
\AbstractEntityPersister.cs:3713
 
NHibernate.Event.Default.DefaultLoadEventListener.CreateProxyIfNecessary
(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad,
LoadType options, IPersistenceContext persistenceContext) in C:
\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src\NHibernate\Event
\Default\DefaultLoadEventListener.cs:223
   NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad
(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad,
LoadType options) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Event\Default\DefaultLoadEventListener.cs:154
   NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent
event, LoadType loadType) in C:\SourceCode\shamu\vendor\NHibernate
\2.1.0.GA\src\NHibernate\Event\Default\DefaultLoadEventListener.cs:86
   NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType
loadType) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Impl\SessionImpl.cs:2485
   NHibernate.Impl.SessionImpl.InternalLoad(String entityName, Object
id, Boolean eager, Boolean isNullable) in C:\SourceCode\shamu\vendor
\NHibernate\2.1.0.GA\src\NHibernate\Impl\SessionImpl.cs:1380
   NHibernate.Type.EntityType.ResolveIdentifier(Object id,
ISessionImplementor session) in C:\SourceCode\shamu\vendor\NHibernate
\2.1.0.GA\src\NHibernate\Type\EntityType.cs:386
   NHibernate.Type.EntityType.ResolveIdentifier(Object value,
ISessionImplementor session, Object owner) in C:\SourceCode\shamu
\vendor\NHibernate\2.1.0.GA\src\NHibernate\Type\EntityType.cs:424
   NHibernate.Engine.TwoPhaseLoad.InitializeEntity(Object entity,
Boolean readOnly, ISessionImplementor session, PreLoadEvent
preLoadEvent, PostLoadEvent postLoadEvent) in C:\SourceCode\shamu
\vendor\NHibernate\2.1.0.GA\src\NHibernate\Engine\TwoPhaseLoad.cs:78
   NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList
hydratedObjects, Object resultSetId, ISessionImplementor session,
Boolean readOnly) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Loader\Loader.cs:589
   NHibernate.Loader.Loader.DoQuery(ISessionImplementor session,
QueryParameters queryParameters, Boolean returnProxies) in C:
\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src\NHibernate\Loader
\Loader.cs:457
   NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections
(ISessionImplementor session, QueryParameters queryParameters, Boolean
returnProxies) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Loader\Loader.cs:233
   NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session,
Object id, IType identifierType, Object optionalObject, String
optionalEntityName, Object optionalIdentifier, IEntityPersister
persister) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Loader\Loader.cs:1382
   NHibernate.Loader.Entity.AbstractEntityLoader.Load
(ISessionImplementor session, Object id, Object optionalObject, Object
optionalId) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Loader\Entity\AbstractEntityLoader.cs:42
   NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id,
Object optionalObject, ISessionImplementor session) in C:\SourceCode
\shamu\vendor\NHibernate\2.1.0.GA\src\NHibernate\Loader\Entity
\AbstractEntityLoader.cs:37
   NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id,
Object optionalObject, LockMode lockMode, ISessionImplementor session)
in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src\NHibernate
\Persister\Entity\AbstractEntityPersister.cs:3411
   NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource
(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad,
LoadType options) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Event\Default\DefaultLoadEventListener.cs:341
   NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent
event, IEntityPersister persister, EntityKey keyToLoad, LoadType
options) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Event\Default\DefaultLoadEventListener.cs:319
   NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent
event, IEntityPersister persister, EntityKey keyToLoad, LoadType
options) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Event\Default\DefaultLoadEventListener.cs:103
   NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent
event, LoadType loadType) in C:\SourceCode\shamu\vendor\NHibernate
\2.1.0.GA\src\NHibernate\Event\Default\DefaultLoadEventListener.cs:86
   NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType
loadType) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate\Impl\SessionImpl.cs:2485
   NHibernate.Impl.SessionImpl.ImmediateLoad(String entityName, Object
id) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src\NHibernate
\Impl\SessionImpl.cs:1361
   NHibernate.Proxy.AbstractLazyInitializer.Initialize() in C:
\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src\NHibernate\Proxy
\AbstractLazyInitializer.cs:70
   NHibernate.Proxy.AbstractLazyInitializer.GetImplementation() in C:
\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src\NHibernate\Proxy
\AbstractLazyInitializer.cs:154
   NHibernate.ByteCode.Castle.LazyInitializer.Intercept(IInvocation
invocation) in C:\SourceCode\shamu\vendor\NHibernate\2.1.0.GA\src
\NHibernate.ByteCode.Castle\LazyInitializer.cs:61


On Aug 24, 9:25 am, Stefan Steinegger <[email protected]>
wrote:
> How does the line of code exactly look like, where the null reference
> exception occurs? And where is this line of code?
>
> On 24 Aug., 16:03, Seth Goldstein <[email protected]> wrote:
>
> > The code is essentially:
>
> > class ParentClass
> > {
> >   private int _myProperty;
>
> >   ParentClass()
> >   {
> >   }
>
> >   public virtual int MyProperty()
> >   {
> >     get; set;
> >   }
>
> > }
>
> > class ChildClass : ParentClass
> > {
> >   ChildClass()
> >   {
> >     int myPropertyValue = base.MyProperty()
> >   }
>
> > }
>
> > With mapping files similar to:
>
> > <class name="ParentClass" table="`ParentClass`" lazy="false">
> >         <id name="Id" access="field.camelcase-underscore">
> >                 <column name="id" not-null="true" />
> >                 <generator class="identity"/>
> >         </id>
> >         <property name="MyProperty" access="field.camelcase-underscore">
> >                 <column name="my_property" not-null="true" />
> >         </property>
> > </class>
>
> > <joined-subclass name="ChildClass" table="`ChildClass`"
> > extends="ParentClass" lazy="false">
> >         <key column="child_id" foreign-key="parent_id"/>
> > </joined-subclass>
>
> > On Aug 24, 12:58 am, Fabio Maulo <[email protected]> wrote:
>
> > > the code please
>
> > > 2009/8/21 Seth Goldstein <[email protected]>
>
> > > > We have run into a problem with the latest version of NHibernate that
> > > > has us totally stumped.  We have an inherited table schema using
> > > > joined-subclasses in the mapping file.  And the business layer matches
> > > > this schema.  In the constructor of one of the inherited classes, it
> > > > tries to reference a property on the parent object, but fails with an
> > > > “object reference not set to an instance of an object” exception.  In
> > > > that code, I am a proxy and it is trying to reference that property
> > > > fails since the property is on the object itself but not the proxy?
> > > > This used to work just fine in NHibernate 1.2, but fails since our
> > > > upgrade to 2.1 GA.  Do you have any ideas that might assist us?
> > > > Thanks a lot for any information you can provide.  Will a call stack
> > > > help?  Thanks again!
>
> > > --
> > > Fabio Maulo
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to