Suppose I have a mapping kind of like this one (from the reference manual):
Code:
<class name="eg.Node">
<id name="id" column="id"/>
....
<bag name="accessibleTo" table="node_access" lazy="true">
<key column="to_node_id"/>
<many-to-many class="eg.Node" column="from_node_id"/>
</bag>
<!-- inverse end -->
<bag name="accessibleFrom" table="node_access" inverse="true" lazy="true">
<key column="from_node_id"/>
<many-to-many class="eg.Node" column="to_node_id"/>
</bag>
</class>
What if I changed it to:
Code:
<class name="eg.Node">
<id name="id" column="id"/>
....
<bag name="accessibleTo" table="node_access" lazy="true" cascade="all-delete-orphan">
<key column="to_node_id"/>
<many-to-many class="eg.Node" column="from_node_id"/>
</bag>
<!-- inverse end -->
<bag name="accessibleFrom" table="node_access" inverse="true" lazy="true">
<key column="from_node_id"/>
<many-to-many class="eg.Node" column="to_node_id"/>
</bag>
</class>
This doesn't have any chance of working, does it? I assume not, since you might actually have cycles in your graph. My guess is that if you have one node X that is accessibleTo two other nodes Y and Z, and you remove X from Y, Hibernate will delete X even though it is still accessible from Z (and probably cause a constraint violation). Right?
Cheers!
Rob