I have a User and a set of Authorities in a one-to-many relationship:
User.hbm.xml:
<set name="authorities" table="authorities" cascade="all-delete-orphan">
<key column="user_id" />
<one-to-many class="com.ebisent.domain.Authority" />
</set>
When I delete a user, I want to delete the authorities as well, but what is happening is that the child table's foreign key (authorities.user_id) is set to null instead. Then I get the following error and the User delete is rolled back:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
The authorities.user_id update to null is not rolled back, however.
How can I delete Authorities when I delete the parent User?
EDIT: I got this working by explicitly deleting the authorities, calling refresh() on the user, then deleting the user, but I would like to know the "right" way to do this.