Hi,
I have a class called Term that has a many-to-one mapping to a class called Location. This relationship is
optional. I have the mapping set as:
Code:
<many-to-one column="locationOID" name="Location" not-null="false" class="NetPark.Core.Location"/>
When trying to delete the object (whereas the Location property is null) I get the exception below.
It appears that NHibernate wants to resolve the relationship even though cascade="none". In addition it doesn't seem to understand the relationship is optional. In general, are optional relationships in NHibernate unsupported? Is there a way around this? If not, this is a major show-stopper for us!!
Please let me know. thanks.
Code:
2005-06-02 07:23:16,161 [2336] DEBUG NHibernate.Impl.SessionImpl [] <> - resolving associations for: [NetPark.Core.Term#TEST.Red]
2005-06-02 07:23:20,647 [2336] ERROR NHibernate.ADOException [] <> - could not load object
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: NHibernate
at NHibernate.Property.BasicSetter.Set(Object target, Object value)
at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)
2005-06-02 07:23:20,707 [2336] ERROR NHibernate.Proxy.LazyInitializer [] <> - Exception initializing proxy.
Exception: NHibernate.ADOException
Message: could not load object
Source: NHibernate
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)
at NHibernate.Impl.SessionImpl.ImmediateLoad(Type clazz, Object id)
at NHibernate.Proxy.LazyInitializer.Initialize()
at NHibernate.Proxy.LazyInitializer.InitializeWrapExceptions()
Nested Exception
Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: NHibernate
at NHibernate.Property.BasicSetter.Set(Object target, Object value)
at NHibernate.Persister.AbstractEntityPersister.SetPropertyValues(Object obj, Object[] values)
at NHibernate.Impl.SessionImpl.InitializeEntity(Object obj)
at NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object[] values, IType[] types, Object optionalObject, Object optionalID)
at NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, Object optionalIdentifier)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId)
at NHibernate.Loader.EntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject)
at NHibernate.Persister.EntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoad(Type theClass, Object id, Object optionalObject, LockMode lockMode, Boolean checkDeleted)