Hi,
Pulling my hair out over this one :o
If I understand this correctly, if I have a one to many mapping and I delete a child from the parent's collection, then it should be deleted in the database.
For example, my parent mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="XXX.BusinessEntities" assembly="XXX">
<class name="ComplianceCriteria" table="ComplianceCriteria" dynamic-update="true">
<id name="Id" column="CC_ID" type="Int32">
<generator class="identity" />
</id>
<!-- Standard Audit Properties -->
<version name="RowVersion" column="RowVersion" type="Int32" />
<property name="CreationUser" column="CreationUser" type="String" />
<property name="CreationDateTime" column="CreationDateTime" type="DateTime" />
<property name="LastUpdateUser" column="LastUpdateUser" type="String" />
<property name="LastUpdateDateTime" column="LastUpdateDateTime" type="DateTime" />
<!-- End -->
<!-- One-to-Many Collections -->
<bag name="LetterTexts" table="ComplianceCriteriaLetterText" cascade="none" inverse="false" lazy="false">
<key column="CLT_CC_ID" />
<one-to-many class="ComplianceLetterText"></one-to-many>
</bag>
</class>
</hibernate-mapping>
and my child mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="XXX.BusinessEntities" assembly="XXX">
<class name="ComplianceLetterText" table="ComplianceCriteriaLetterText" dynamic-update="true">
<id name="Id" column="CLT_ID" type="Int32">
<generator class="identity" />
</id>
<!-- Standard Audit Properties -->
<version name="RowVersion" column="RowVersion" type="Int32" />
<property name="CreationUser" column="CreationUser" type="String" />
<property name="CreationDateTime" column="CreationDateTime" type="DateTime" />
<property name="LastUpdateUser" column="LastUpdateUser" type="String" />
<property name="LastUpdateDateTime" column="LastUpdateDateTime" type="DateTime" />
<!-- End -->
<many-to-one name="ComplianceCriteria" column="CLT_CC_ID" insert="true" update="true" />
</class>
</hibernate-mapping>
So if I execute the following for an existing row with a child LetterText:
Code:
ComplianceCriteria cc = (ComplianceCriteria)session.Load(cc.GetType(), 2);
cc.LetterTexts.RemoveAt(0);
session.BeginTransaction();
session.SaveOrUpdate(cc);
session.Transaction.Commit();
I get the following message:
Code:
"Cannot insert the value NULL into column 'CLT_CC_ID', table 'LgsDev.dbo.ComplianceCriteriaLetterText'; column does not allow nulls. UPDATE fails."
When working through the source code I see that the OneToManyPersister.GenerateDeleteRowString() creates this statement.
What have I missed? Should NHibernate be deleting this row for me or do I have to do it manually? If it can, then what do I need to change in my mapping to make this happen?
Thanks in advance,
Mike