(N)Hibernate: deleting orphaned ternary association rows when either associated row is deleted.
Posted
by anthony
on Stack Overflow
See other posts from Stack Overflow
or by anthony
Published on 2010-05-06T01:55:01Z
Indexed on
2010/05/06
1:58 UTC
Read the original article
Hit count: 307
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?
© Stack Overflow or respective owner