When creating a new class I was hoping for 2 insert statements, but instead I get an Insert and an Update.
Code:
<class name="NH_FF_TestApp.Class1, NH-FF-TestApp" table="ATable1">
<id name="Id" >
<generator class="assigned" />
</id>
<property name="Field1" />
</class>
<class name="NH_FF_TestApp.Class2, NH-FF-TestApp" table="ATable2">
<id name="Id" >
<generator class="assigned" />
</id>
<many-to-one name="Object1" class="NH_FF_TestApp.Class3, NH-FF-TestApp" column="Object1Id" cascade="all"/>
<property name="Field1" />
</class>
<class name="NH_FF_TestApp.Class3, NH-FF-TestApp" table="ATable3">
<id name="Id" >
<generator class="assigned" />
</id>
<property name="Field1" />
</class>
Code:
{
Configuration cfg = new Configuration();
cfg.AddAssembly("NH-FF-TestApp");
NH.ISessionFactory factory = cfg.BuildSessionFactory();
_session = factory.OpenSession();
Class2 class2 = new Class2();
class2.Id = "C2" + DateTime.Now.ToString().Replace(" ", "");
class2.Field1 = "aaaaaa";
Class3 class3 = new Class3();
class3.Id = "C3" + DateTime.Now.ToString().Replace(" ", "");
class3.Field1 = "class3";
class2.Object1 = class3;
_session.Save(class2);
_session.Flush();
This generates an insert statement for ATable2 and an update statement for ATable3 which fails as there is nothing to update.
Regards
Tim