I have an NHibernate entity which contains a many-to-many list of related items. When a certain property of the entity changes, a database trigger is called that removes all associations between the entity and any entities that it is joined to. However, NHibernate throws a StaleStateException with a message along the lines of:
Batch update returned unexpected row count from update; actual row count: 0; expected: N
This presents a problem because it causes a rollback of the transaction and the entity is not saved. This arises because when the entity is updated, all of the entities in the many-to-many collection are also updated by NHibernate, but they no longer exist because of the trigger, which then causes the updates to fail giving back a row count of 0.
I unfortunately cannot change this database behavior and implement this entirely in NHibernate.
Is there anyway to prevent this behavior or update the entity without updating the entities in the many-to-many association?