I'm getting a StaleStateException when I try to delete an object. The message is "Unexpected row count: 0; expected: 1". The issue seems to be that Hibernate is deleting from the bag twice:
NHibernate.SQL: 2010-12-05 03:42:04,950 [11] DEBUG NHibernate.SQL [(null)] - DELETE FROM FieldInstance WHERE fkObjectInstanceId = @p0;@p0 = 6 [Type: Int32 (0)] NHibernate.SQL: 2010-12-05 03:42:04,968 [11] DEBUG NHibernate.SQL [(null)] - DELETE FROM FieldInstance WHERE fieldInstanceId = @p0;@p0 = 19 [Type: Int32 (0)]
The delete on fkObjectInstanceId is sufficient, and removes any items that would be removed by deleting the specific field identifier. Here is my mapping:
<bag name="Fields" table="FieldInstance" lazy="true" cascade="all"> <key column="fkObjectInstanceId"/> <many-to-many class="FieldInstance" column="fieldInstanceId" /> </bag> The thing is, there is a many-to-many here and the column is the tables primary key. This is because it is used to generate the field instance class.
I couldn't see an attribute to tell NHibernate NOT to prioritise for deletion.
Suggestions?
|