I have one class of self-regulation. The child has a link to the parent, and the parent has a list of children. Since the list of children is ordered, I am trying to match the relation using NHibernate.
This is my mapping:
<class name="MyClass"> <id name="Id"> <generator class="native"/> </id> <list name="Children" cascade="delete" inverse="true"> <key column="ParentId"/> <index column="ListOrder"/> <one-to-many class="MyClass"/> </list> <many-to-one name="Parent" class="MyClass" column="ParentId"/> </class>
The problem I'm running into is when I have a child ↔ parent bi-directional display, the list index (ListOrder) is not updated in the database when I do my CRUD dance. This means that when I, for example, delete a child, I get holes in the list of children after saving to the database and selecting the parent. If I remove bidirectionality without having many-to-one from the children of the parent element (and not the opposite = true), the ListOrder will be updated correctly.
Have any of you seen this before? Is there a simple solution?
mapping orm nhibernate- nhibernate-mapping
Thomas Lundström
source share