i have a one to many and i'm trying to delete the parent + children, however the database (not mine but i have to write to it anyway) has update triggers that insert rows into history tables that have a PK on th entity id + the version column of the entity. When I modify the collection NH is updating the entity before deleting it but it is not incrementing the version causing the trigger to error
The NH logs detect the collection property is dirty which is why I figure it is trying to save my entity (although the entity is deleted so I don't think it should be trying to save it)
My entity is using <version>.
Mappings:
Code:
<hibernate-mapping auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name=WebUser, Web" table="WebUser">
<id name="WebUserID" access="property" column="WebUserID" type="Int32" unsaved-value="0">
<generator class="SerialIdentifierGenerator, Web">
</generator>
</id>
<version name="Version" access="field.camelcase-underscore" column="Version" type="Int32" />
<property name="ModifyDate" access="property" type="System.DateTime">
<column name="ModifyDate"/>
</property>
<property name="UserID" access="property" type="Int32">
<column name="UserID"/>
</property>
<property name="UserName" access="property" type="String">
<column name="UserName"/>
</property>
<property name="Password" access="property" type="String">
<column name="Password"/>
</property>
<property name="FirstName" access="property" type="String">
<column name="FirstName"/>
</property>
<property name="LastName" access="property" type="String">
<column name="LastName"/>
</property>
<property name="EmailAddress" access="property" type="String">
<column name="EmailAddress"/>
</property>
<property name="SecurityFlags" access="property" type="Int32">
<column name="SecurityFlags"/>
</property>
<property name="LastLogin" access="property" type="System.DateTime">
<column name="LastLogin"/>
</property>
<property name="PasswordHint" access="property" type="String">
<column name="PasswordHint"/>
</property>
<property name="SecureQuestion1" access="property" type="String">
<column name="SecureQuestion1"/>
</property>
<property name="SecureAnswer1" access="property" type="String">
<column name="SecureAnswer1"/>
</property>
<property name="SecureQuestion2" access="property" type="String">
<column name="SecureQuestion2"/>
</property>
<property name="SecureAnswer2" access="property" type="String">
<column name="SecureAnswer2"/>
</property>
<property name="CreationTime" access="property" type="System.DateTime">
<column name="CreationTime"/>
</property>
<bag name="WebUserAccounts" access="nosetter.camelcase-underscore" table="WebUserAccount" lazy="false" inverse="true" cascade="save-update">
<key column="WebUserID" />
<one-to-many class="WebUserAccount, Web" />
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping auto-import="true" default-lazy="false" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.2">
<class name="WebUserAccount, Web" table="WebUserAccount">
<id name="WebUserAccountID" access="property" column="WebUserAccountID" type="Int32" unsaved-value="0">
<generator class="SerialIdentifierGenerator, Web">
</generator>
</id>
<version name="Version" access="field.camelcase-underscore" column="Version" type="Int32" />
<property name="ModifyDate" access="property" type="System.DateTime">
<column name="ModifyDate"/>
</property>
<property name="UserID" access="property" type="Int32">
<column name="UserID"/>
</property>
<property name="SecurityFlags" access="property" type="Int32">
<column name="SecurityFlags"/>
</property>
<property name="AccountID" access="property" type="Int32">
<column name="AccountID"/>
</property>
<many-to-one name="WebUser" access="property" class="WebUser, Web" column="WebUserID" />
</class>
</hibernate-mapping>
Code:
foreach (WebUser toDelete in WebUser.FindAll())
{
toDelete.WebUserAccounts.Clear();
toDelete.Delete();
}