nhibernate will not cascade delete childs

Posted by marn on Stack Overflow See other posts from Stack Overflow or by marn
Published on 2010-03-05T15:14:16Z Indexed on 2010/03/08 8:21 UTC
Read the original article Hit count: 717

The scenario is as follows,

I have 3 objects (i simplified the names) named Parent, parent's child & child's child
parent's child is a set in parent, and child's child is a set in child.

mapping is as follows (relevant parts)

parent

<set name="parentset"
     table="pc-table"
     lazy="false"
     fetch="subselect"
     cascade="all-delete-orphan"
     inverse="true">
  <key column=FK_ID_PC" on-delete="cascade"/>
  <one-to-many class="parentchild,parentchild-ns"/>
</set>

parent's child

<set name="childset"
     table="cc-table"
     lazy="false"
     fetch="subselect"
     cascade="all-delete-orphan"
     inverse="true">
  <key column="FK_ID_CC" on-delete="cascade"/>
  <one-to-many class="childschild,childschild-ns"/>
</set>

What i want to achieve is that when i delete the parent, there would be a cascade delete all the way trough to child's child. But what currently happens is this.

(this is purely for mapping test purposes) getting a parent entity (works fine)

IQuery query = session.CreateQuery("from Parent where ID =" + ID);
IParent doc = query.UniqueResult<Parent>();

now the delete part

session.Delete(doc);
transaction.Commit();

After having solved the 'cannot insert null value' error with cascading and inverse i hopes this would now delete everything with this code, but only the parent is being deleted.

Did i miss something in my mapping which is likely to be missed? Any hint in the right direction is more than welcome!

© Stack Overflow or respective owner

Related posts about c#

Related posts about nhibernate