I have a user and a set of authority 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 also want to remove the permissions, but what happens is that the foreign key of the child table (authority.user_id) is null. Then I get the following error, and deleting the user is canceled:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
Updating .user_id privileges to null is not a rollback.
How can I remove privileges when deleting a parent user?
EDIT: I got this working by explicitly deleting privileges by calling refresh()on the user and then deleting the user, but I would like to know the โrightโ way to do this.
outis