Hibernate version:
1.0.2.0
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<hibernate-mapping default-access="field.pascalcase-m-underscore" xmlns="urn:nhibernate-mapping-2.0">
<class name="NHibernate.Bugs.Base, NHibernate.Bugs" table="Base" proxy="NHibernate.Bugs.Base, NHibernate.Bugs">
<id name="ObjectId" type="Int32" unsaved-value="-1">
<generator class="native" />
</id>
<version column="VersionCounter" name="VersionCounter" type="Int32" />
</class>
<joined-subclass name="NHibernate.Bugs.Parent, NHibernate.Bugs" table="Parent" proxy="NHibernate.Bugs.Parent, NHibernate.Bugs" extends="NHibernate.Bugs.Base, NHibernate.Bugs">
<key column="ObjectId" />
<set name="Childs" lazy="true" inverse="true">
<key column="Owner" />
<one-to-many class="NHibernate.Bugs.Child, NHibernate.Bugs" />
</set>
</joined-subclass>
<class name="NHibernate.Bugs.Child, NHibernate.Bugs" table="Child" proxy="NHibernate.Bugs.Child, NHibernate.Bugs">
<id name="ObjectId" type="Int32" unsaved-value="-1">
<generator class="native" />
</id>
<version column="VersionCounter" name="VersionCounter" type="Int32" />
<many-to-one name="Owner" column="Owner" class="NHibernate.Bugs.Parent, NHibernate.Bugs" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Parent obj1 = new Parent();
ses.Save(obj1);
ses.Save(new Child(obj1));
The code inside class structure relevant to exception creation is:
public class Parent : Base
{
private ISet m_Childs;
public void AddChild(Child child)
{
// The lazy initialization of ISet is crucial. Without that, the exception does not occure
if (m_Childs == null)
m_Childs = new HashedSet();
m_Childs.Add(child);
}
public virtual ICollection Childs
{
get { return m_Childs; }
}
}
public class Child
{
public Child() : base() { }
public Child(Parent owner) : base()
{
m_Owner = owner;
m_Owner.AddChild(this);
}
/*
....
*/
}
Full stack trace of any exception that occurs:Code:
NHibernate.Bugs.Bug1Tester.GenerateNullReferenceException : NHibernate.ADOException : could not update: [NHibernate.Bugs.Parent#1]
----> System.NullReferenceException : Object reference not set to an instance of an object.
at NHibernate.Persister.NormalizedEntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Boolean[] includeTable, Object oldVersion, Object obj, SqlString[] sql, ISessionImplementor session)
at NHibernate.Persister.NormalizedEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Bugs.Bug1Tester.GenerateNullReferenceException() in C:\Projects\NHibernate.Bugs\Bug1Classes.cs:line 90
--ADOException
at NHibernate.Driver.DriverBase.GenerateCommand(Dialect dialect, SqlString sqlString)
at NHibernate.Impl.BatcherImpl.Generate(SqlString sqlString)
at NHibernate.Impl.BatcherImpl.PrepareCommand(SqlString sql)
at NHibernate.Persister.NormalizedEntityPersister.Update(Object id, Object[] fields, Boolean[] includeProperty, Boolean[] includeTable, Object oldVersion, Object obj, SqlString[] sql, ISessionImplementor session)
Name and version of the database you are using:
SQL Server 2005