-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: <array>, cascade="all-delete-orphan" and upd
PostPosted: Tue Jan 16, 2007 7:48 am 
Newbie

Joined: Tue Jan 16, 2007 5:42 am
Posts: 4
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

_________________
Christian Haessig
System, Network and DB administrator / DB engineer
IRCAD/EITS
mailto:christian.haessig@ircad.u-strasbg.fr


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 16, 2007 3:22 pm 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Could post the code you use to remove the child from the parent collection?
I haven't used the <array/> but it seems to me that you may not be removing the reference on both sides.

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 3:54 am 
Newbie

Joined: Tue Jan 16, 2007 5:42 am
Posts: 4
Thanks for reply,

sure, here's the code which removes a child :

Code:
       
wsPat.Studies[1] = null;   // remove the instance of the child
WSStudy[] arStudies = wsPat.Studies;  // resize the array
Array.Resize(ref arStudies, wsPat.Studies.Length - 1);
wsPat.Studies = arStudies;

session.update(wsPat);


The first line may not be necessary ...

Thanks for your help,

Christian

_________________
Christian Haessig
System, Network and DB administrator / DB engineer
IRCAD/EITS
mailto:christian.haessig@ircad.u-strasbg.fr


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 8:45 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Well for starters you can't just reassign a Collection to a Parent.Collection, that doesn't work. It is more appropriate to do something like Parent.Collection.Remove(object) or RemoveAt(). Since you have cascades set the deletion from the collection will delete the "object".

I also have not used the <array> tag, but in the example you show, you need to set inverse="true" on the <many-to-one>. Since you haven't done that, you are getting the dreaded NULL problem. See the FAQ for more info:

http://www.hibernate.org/359.html#A10

hth,

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 18, 2007 6:40 am 
Newbie

Joined: Tue Jan 16, 2007 5:42 am
Posts: 4
Hi,

thanks for your advices.

Actually, I know all this, but an Array object does not have a Remove or RemoveAt method ( or, at least, it will throw an NotSupportedException ).
And as I already told, I have to use Arrays. I know it's not the simplest collection object, but I have no other choice in my case.

Concerning the inverse="true", could you be more precise ? I saw in the documentation that inverse="true" is not supported for <array>.

Well, I'm not an easy case :)

Christian

_________________
Christian Haessig
System, Network and DB administrator / DB engineer
IRCAD/EITS
mailto:christian.haessig@ircad.u-strasbg.fr


Top
 Profile  
 
 Post subject: same problem here
PostPosted: Fri Jun 08, 2007 4:40 am 
Newbie

Joined: Fri May 25, 2007 6:34 am
Posts: 2
did you manage to find a solution?

I have exactly the same problem: it seems that all-delete-orphan doesn't work for array


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 07, 2007 11:23 am 
Newbie

Joined: Wed Sep 05, 2007 12:22 pm
Posts: 8
we also have this issue - has anyone used an <array> collection?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.