Hi,
I have come across an interesting problem. Take a look at the simple mapping below. Class A is in recursive relationship with it self and save-update cascade option is turned on. A is also in parent/child relationship with class B with the same cascade option turned on.
The problem I am experiencing is when a remote client in a detached graph adds x many Bs to an A and saves it back on the server side. I am not sure if this happens only with detached graphs.
Back to the problem. There are two scenarios. In the first one when x many Bs are added to a leaf A then everything works as expected. However, in a second scenario if x many Bs are added to a non-leaf A then save is cascaded to all the ancestors of A. Thus in the end one ends up with <number of A's ancestors>*<number of x> many object in a database.
Is this the proper behaviour? If yes, how do I add Bs to non-leaf A and avoid having cascading add of Bs to A's ancestors but at the same time keep cascade semantics of A's recursive relationship to itself?
All the best,
Vladimir
Code:
<class name="A" table="A">
<id name="id" unsaved-value="0" column="id" type="long">
<generator class="increment"/>
</id>
<set name="bs" lazy="false" inverse="true" cascade="save-update">
<key column="parent"/>
<one-to-many class="B"/>
</set>
<set name="children" lazy="false" inverse="true" cascade="save-update">
<key column="parent"/>
<one-to-many class="A"/>
</set>
<many-to-one name="parent" class="A"/>
</class>
<class name="B" table="B">
<id name="id" unsaved-value="0" column="id" type="long">
<generator class="increment"/>
</id>
<many-to-one name="parent" class="A"/>
</class>