-->
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: A cascading question (probably)
PostPosted: Fri May 06, 2005 9:31 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
I have a customer class which contains a Set of addresses. Adding an address to the customer and saving the customer works fine, as does modifying an address. However, removing an address from the customer and saving the customer does NOT delete the customer from the database. The log shows that the address has been removed successfully from the customer object at the point the customer is saved (with saveOrUpdateCopy). But the address remains in the database. What have I got wrong here?

Here's the relevant section from the Customer mapping:

<set
name="addresses"
lazy="true"
inverse="true"
cascade="all"
sort="unsorted"
>

<key column="customer_id">
</key>

<one-to-many
class="myproject.om.Address"
/>

</set>

This is from the Address mapping:

<many-to-one
name="customer"
class="myproject.om.Customer"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="customer_id"
/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 9:49 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
all-delete-orphan?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 10:04 am 
Newbie

Joined: Thu Apr 28, 2005 10:25 am
Posts: 7
Location: Italy
hi anthony.
maybe my reply is out of place, but isn' t the "all" cascade here the right choice?
i mean, isn' t the "all-delete-orphans" appropriate for the following situation (assuming the mapping presented here) :

if a customer is delete, then remove all the addresses populating the set , because they are weak entities and they have no father left.

while the "delete " cascade behavior is intended for:

if an address populating the set of a customer is deleted, then remove it from the db when the customer is persisted.

Am I getting it right?

_________________
~ Luca Ghirotti ~
Technology Reply


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 10:06 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
Yes, this did the job. Thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 10:07 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
ghiro wrote:
hi anthony.
maybe my reply is out of place, but isn' t the "all" cascade here the right choice?
i mean, isn' t the "all-delete-orphans" appropriate for the following situation (assuming the mapping presented here) :

if a customer is delete, then remove all the addresses populating the set , because they are weak entities and they have no father left.

while the "delete " cascade behavior is intended for:

if an address populating the set of a customer is deleted, then remove it from the db when the customer is persisted.

Am I getting it right?


It solved my problem, but I too am puzzled.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 10:11 am 
Newbie

Joined: Thu Apr 28, 2005 10:25 am
Posts: 7
Location: Italy
J2R do you mind posting the piece of code where you open the session and perform the delete? Thanks.

_________________
~ Luca Ghirotti ~
Technology Reply


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 10:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
cascade= all implies cascade=delete
that means, if you delete the parent, the children are deleted, but if a child is 'removed' from the collection, it is not deleted.

delete-orphan means "please delete children when they are orphan", so if you remove a child from a collection, it is deleted.
This is what you need in your case.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 06, 2005 10:14 am 
Newbie

Joined: Thu Apr 28, 2005 10:25 am
Posts: 7
Location: Italy
thanks. that was wellcome.

_________________
~ Luca Ghirotti ~
Technology Reply


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.