I have found the source of the problem, but am not sure if it is a bug in NHibernate or an implementation detail.
The following uses existing NHibernate domain model to demonstrate how I create new objects.
Code:
using( ISession s1 = OpenSession() )
using( ITransaction t1 = s1.BeginTransaction() )
{
M parent = new M();
N n = new N();
n.String = "0";
parent.AddChildren( n );
s1.Save( parent );
pid = Convert.ToInt64(s1.GetIdentifier(parent));
Assert.IsTrue(pid > 0);
Assert.IsTrue(Convert.ToInt64(s1.GetIdentifier(n)) > 0);
t1.Commit();
}
This works fine. The following demonstrates how I would update and object model
Code:
using( ISession s2 = OpenSession() )
using( ITransaction t2 = s2.BeginTransaction() )
{
M parentLoaded = (M) s2.Load(typeof(M), pid);
N n = new N();
n.String = "P";
parentLoaded.AddChildren( n );
s2.SaveOrUpdate(parentLoaded);
[b] s2.Flush();[/b]
Assert.IsTrue(Convert.ToInt64(s2.GetIdentifier(n)) > 0);
t2.Commit();
}
If I do not include an ISession.Flush() before I access the generated identity property, the property will return the unsaved-value (0). However, with the Flush, it works. I only bring this up because the Flush is not required when creating a completely new object model and I am wondering if this a bug or required to simplify update implementation.
Thanks,
craig