-->
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.  [ 8 posts ] 
Author Message
 Post subject: cascade="all-delete orphan
PostPosted: Thu Dec 15, 2005 3:00 pm 
Beginner
Beginner

Joined: Tue Dec 28, 2004 11:30 am
Posts: 32
Hello guys,

cascade= all-delete-orphan is failing
MY use case

- Load an object from the database in session 1; close session
- Make changes to the Party object such as remove one of the emails from the email list
- saveOrupdate party object in session 2.
- the deleted email object is not being removed from the database.

I dont get any errors from hibernate and i dont see and delete sql being generated from Hibernate. Although if i make changes to the email object those changes are saved .

So my question is what am i doing wrong
Thank you

Hibernate version:3.0.5

Mapping documents:
Party.hbm.xml
<class name="PartyImpl" polymorphism="implicit" proxy="PartyImpl" table="party">
<id column="party_id" name="partyID" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<discriminator column="discriminator_type" type="string"/>
<many-to-one class="ObjectTypeImpl" column="object_type_id" insert="true" name="objectType" update="true"/>
<property column="note" insert="true" name="note" type="string" update="true"/>
<set cascade="all-delete-orphan" inverse="true" lazy="true" name="addressList" outer-join="false" table="address">
<key column="party_id"/>
<one-to-many class="AddressImpl"/>
</set>

<set cascade="all-delete-orphan" inverse="true" lazy="true" name="emailList" outer-join="false" table="email">
<key column="party_id"/>
<one-to-many class="EmailImpl"/>
</set>

<set cascade="all-delete-orphan" inverse="true" lazy="true" name="phoneList" outer-join="false" table="phone">
<key column="party_id"/>
<one-to-many class="PhoneImpl"/>
</set>
<bag batch-size="100" cascade="delete" lazy="true" name="associatedObjects" outer-join="false">
<key column="master_object_id"/>
<one-to-many class="ObjectAssociationImpl"/>
</bag>
<bag batch-size="100" cascade="delete" lazy="true" name="associations" outer-join="false">
<key column="associated_object_id"/>
<one-to-many class="ObjectAssociationImpl"/>
</bag>
<subclass discriminator-value="OT4" name="org.wgbh.scape.domain.HumanImpl" proxy="org.wgbh.scape.domain.HumanImpl">
<property column="name_human_first" insert="true" name="firstName" type="string" update="true">
</property>
</subclass>
</class>

Email.hbm.xml
<class name="EmailImpl" polymorphism="implicit" proxy="EmailImpl" table="email">
<id column="email_id" name="emailID" type="string" unsaved-value="null">
<generator class="uuid.hex"/>
</id>
<many-to-one class="ObjectTypeImpl" column="object_type_id" name="objectType"/>

<many-to-one class="PartyImpl" column="party_id" insert="true" name="party" outer-join="false" update="true">
</many-to-one>

<property column="email" insert="true" name="emailAddress" type="string" update="true">
</property>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 15, 2005 6:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
H3 allows multiple cascade options thus its now two options separated with the comma rather then the combo option, eg,

Code:
cascade='all, delete-orphan'


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 10:10 am 
Beginner
Beginner

Joined: Tue Dec 28, 2004 11:30 am
Posts: 32
Thank you for your response but no that wasn't it. It is still not deleting the row from the database .

I had two email address objects and i deleted one , You can see how only one update is happening. But a delete does not happen .

I have actually turned sql logs on and this is what i see
2005-12-16 09:06:30,994 [http-8080-Processor23] DEBUG org.hibernate.jdbc.AbstractBatcher.log: 324 - update party set object_type_id=?, note=?, ssn=?, name_human_first=?, name_human_middle=?, name_human_last=?, name_human_prefix=?, name_human_suffix=?, description=?, job_title=? where party_id=?
2005-12-16 09:06:31,386 [http-8080-Processor23] DEBUG org.hibernate.jdbc.AbstractBatcher.log: 324 - update email set object_type_id=?, party_id=?, email=? where email_id=?
2005-12-16 09:06:31,390 [http-8080-Processor23] DEBUG org.hibernate.jdbc.AbstractBatcher.log: 324 - update phone set object_type_id=?, work_order_id=?, party_id=?, phone_country_code=?, phone_area_code=?, phone_number=?, phone_extension=? where phone_id=?
......

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 1:06 pm 
Beginner
Beginner

Joined: Tue Dec 28, 2004 11:30 am
Posts: 32
Thinking about this furthur -

cascade= "all-delete-orphan" documentation says

Hibernate deletes any persistent entity instance that has been removed
(dereferenced) from the association( from a collection ) .

So that said in my use case .

My object is a detached object and i delete an object from the list . But again my main root object is detached not ( persistent )
and hence it doesn't see the change.

1. Detached object with no session open
2. remove an object from the list
3. session.saveOrUpdate()
4. And i get the SQL in the previous post with no delete-orphan cascading

SO IF I HAVE THIS

1. Open session
2. Load object
3. remove an object from the list
4. session.saveOrUpdate()

Will that work

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 6:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The all cascade option includes the delete operation, the delete-orphan is for deleting all the children in the case of the parent being deleted. The object needs to be in session for the changes to be detected. Its always best to just try your ideas out to confirm what works or not for your configuration and code base.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 6:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
BTW: I am saying yes to your question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 8:39 pm 
Beginner
Beginner

Joined: Tue Dec 28, 2004 11:30 am
Posts: 32
Code:
the delete-orphan is for deleting all the children in the case of the parent being deleted.


I thought delete-orphan means Hibernate will delete any persistent entity instance that has been removed dereferenced from the association in my case the the collection . and that's when you try to update the main object.
Is that true ? or am i wrong

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 16, 2005 11:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Yes you are correct. Its not an option I use often as I prefer to delete objects directly as its obvious what the intent is.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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.