Reputation: 19854
My Collection mapping file contains the following relationship:
<set inverse="false" lazy="true" name="collectionMembers" sort="unsorted" cascade="save-update,delete-orphan">
<key>
<column name="COLLECTION_CD" />
</key>
<one-to-many class="CollectionMember" />
</set>
CollectionMember mapping file then contains the following bidirectional relationship:
<many-to-one name="collection" class="Collection" lazy="false">
<column name="COLLECTION_CD" length="36" not-null="true" />
</many-to-one>
So a Collection contains a collection of CollectionMembers
The problem I am encountering is that when I attempt to delete a CollectionMember by removing it from the set, I get the following error message:
cannot update ("COLLECTION_MEMBER"."COLLECTION_CD") to NULL
Why is it attempting to perform an update here instead of delete?
Thanks
Upvotes: 0
Views: 3756
Reputation: 30813
Why is it attempting to perform an update here instead of delete?
because inverse="false"
told Hibernate that the collection is responsible for the association which means removing from the collection -> remove the association between the rows -> set foreign key to null
what you propably want is inverse="true" cascade="all-delete-orphan"
Upvotes: 2