-->
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.  [ 4 posts ] 
Author Message
 Post subject: Relationship / cascading problem
PostPosted: Fri Sep 04, 2009 8:44 am 
Newbie

Joined: Fri Sep 04, 2009 8:24 am
Posts: 5
I have three classes: RoutingChain, Status, and Permission. A RoutingChain object has a Permission and a set of Status objects. Which Statuses go into this set is determined by the Permission the RoutingChain has. So when I change the RoutingChain's Permission, its set of Status objects changes accordingly.

My problem is that when I change the Permission for a RoutingChain and generate a new set of Statuses, the old set of Statuses does not get deleted from the database. These old Statuses are successfully disassociated with the RoutingChain -- their ROUTING_CHAIN_ID column goes from the RoutingChain's ID to NULL -- but I want them to be completely deleted from the database altogether, instead of sitting there with no associated RoutingChain.

I know I can do this manually using a custom DAO method, but I'm sure there's some way to set up my hbm relationships such that when a Status's relationship with a RoutingChain is removed, that Status is deleted. Here's how I have my relationship now:

In RoutingChain's hbm:

Code:
<set name="Statuses" cascade="all">
<key column="ROUTING_CHAIN_ID" />
        <one-to-many class="Status"/>
</set>


In Status's hbm:

Code:
<many-to-one
         name="routingChain"
         class="RoutingChain"
         column="ROUTING_CHAIN_ID"
         cascade="none"
/>


Any help would be greatly appreciated!

Thanks,
Erica


Top
 Profile  
 
 Post subject: Re: Relationship / cascading problem
PostPosted: Fri Sep 04, 2009 1:44 pm 
Newbie

Joined: Wed Oct 01, 2008 2:27 pm
Posts: 18
Does it work if instead of cascade="all" you use cascade="all-delete-orphan"?


Top
 Profile  
 
 Post subject: Re: Relationship / cascading problem
PostPosted: Fri Sep 04, 2009 2:37 pm 
Newbie

Joined: Fri Sep 04, 2009 8:24 am
Posts: 5
Yes, that was it! I knew it had to be something simple, but I wasn't sure how to set up the cascade. That worked exactly the way I wanted. Thank you!


Top
 Profile  
 
 Post subject: Re: Relationship / cascading problem
PostPosted: Fri Sep 04, 2009 2:38 pm 
Newbie

Joined: Fri Sep 04, 2009 8:24 am
Posts: 5
Although for the record, it was cascade="all,delete-update", with a comma between "all" and "delete-update", not a dash.


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