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