(N)Hibernate: deleting orphaned ternary association rows when either associated row is deleted.
- by anthony
I have a ternary association table created using the following mapping:
<map name="Associations" table="FooToBar">
<key column="Foo_id"/>
<index-many-to-many class="Bar" column="Bar_id"/>
<element column="AssociationValue" />
</map>
I have 3 tables, Foo, Bar, and FooToBar.
When I delete a row from the Foo table, the associated row (or rows) in FooToBar is automatically deleted. This is good.
When I delete a row from the Bar table, the associated row (or rows) in FooToBar remain, with a stale reference to a Bar id that no longer exists. This is bad.
How can I modify my hbm.xml to remove stale FooToBar rows when deleting from the Bar table?