Hi,
I've a problem when using an array with cascade="all-delete-orphan", during an update of my objects.
The use of <array>, instead of a <set> for example, is necessary due to external constraints.
I have 2 classes : WSPatient, which contains an array of WSStudy. So there is a one-to-many relation between WSPatient and WSStudy.
Both classes derive from WSAbstract.
NHibernate version : 1.0.3
Mapping files :
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="MedicaWS.WSAbstract,App_Code.kokucnts" table="Abstract">
<id name="ObjectID" column="ObjectID" type="Int32" unsaved-value="0" >
<generator class="native"/>
</id>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<joined-subclass name="MedicaWS.WSPatient, App_Code.kokucnts"
extends="MedicaWS.WSParam,App_Code.kokucnts"
table="Patient">
<key column="ID"/>
<property name="Name" column="Name" type="String" length="50"/>
...
<array name="Studies" table="Study" cascade="all-delete-orphan" >
<key column="Patient" />
<index column="StudyIndex" />
<one-to-many class="MedicaWS.WSStudy, App_Code.kokucnts" />
</array>
</joined-subclass>
</hibernate-mapping>
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<joined-subclass name="MedicaWS.WSStudy,App_Code.kokucnts"
extends="MedicaWS.WSParam,App_Code.kokucnts"
table="Study">
<key column="ID"/>
<property name="RisID" column= "RisID" type="String" length="50"/>
...
<many-to-one name="Patient"
class="MedicaWS.WSAbstract,App_Code.kokucnts"
column="Patient" />
</joined-subclass>
</hibernate-mapping>
The problem :
In my database, I've one WSPatient, which has 2 WSStudy in its array.
Reading the objects works very well : I've my WSPatient instance, having 2 WSStudy instances in its Studies array.
But when I try to remove the second study, NHibernate only sets the Patient and StudyIndex fields to NULL, without removing the whole study. And this despite of cascade="all-delete-orphan"
The code is very simple. I build a session, a transaction, call session.Update () and commit the transaction.
Does anyone have information about the use of <array> and cascade="all-delete-orphan" ?
Or even better, a solution to my problem ? :)
Thanks in advance !
Christian