Hi!
I've been having problems removing an object that has references to it. I've searched everywhere, but none of the solutions helped me. Maybe I didn't know what exactly to search for at all...
Here's the problem:
- Assume we have objects Foo and Bar.
- Foo contains a List of Bars.
Foo's mapping file is something like this:
Code:
<hibernate-mapping>
<class name="Foo" table="Foo">
<id name="id" column="PKEY">
<generator class="identity"/>
</id>
<property name="name" column="Name" not-null="true" unique="true"/>
<list name="bars" table="Foo_Bars" lazy="false">
<key column="FK_Foo"/>
<list-index column="SortOrder"/>
<many-to-many column="FK_Bar" class="Bar"/>
</list>
</class>
</hibernate-mapping>
Bar's mapping file actually doesn't relate to the problem, assume its just a simple class with one string attribute or something.
No, when I try to delete the Bar, I get a REFERENCE contraint error, because Foo has references to Bar.
Yes, I could (manually) delete all the references to Bar in the relation table Foo_Bars, before deleting Bar itself, but I will have an unknown number of different objects pointing to the Bar the same way Foo does.
Is my Foo mapping file just plain wrong, or is this problem a very tough one?