I think I have a problem with my cascade logic, but I can't put my finger on it. My model is as follows,
Code:
User(1)-----(*)Entitlement(*)-----(1)Group
(*)
|
Role
I am using a Component relationship between User and Entitlement, and many-to-one between Entitlement and User/Group/Role (See hbm.xml files below).
I get the "Flush during cascade is dangerous" exception whenever I try to delete a User, as follows,
Code:
User user = (User)session.load(User.class, userId) ;
session.delete(user) ;
I've tried iterating and removing each Entitlement, and this works as long as I don't delete the User. If I delete all Entitlements, and then try to delete the User, I get the same "Flush..." exception.
Any Suggestions?
Code:
<hibernate-mapping>
<class name="he2.User" table="SEC2_USER">
<id column="ID" name="id">...</id>
<property column="name" name="name"/>
<set cascade="all" name="entitlements" table="ENTITLEMENT">
<key column="ID"/>
<composite-element class="Entitlement">
<many-to-one cascade="save-update" name="user" column="USER_ID" class="User"/>
<many-to-one cascade="save-update" name="group" column="GROUP_ID" class="Group"/>
<many-to-one cascade="save-update" name="role" column="ROLE_ID" class="Role"/>
</composite-element>
</set>
</class>
<class name="Entitlement" table="ENTITLEMENT">
<id column="ID" name="id">...</id>
<many-to-one cascade="all" class="User" column="USER_ID" name="user"/>
<many-to-one cascade="save-update" class="Group" column="GROUP_ID" name="group"/>
<many-to-one cascade="save-update" class="Role" column="ROLE_ID" name="role"/>
</class>
</hibernate-mapping>
<class name="Group" table="GROUP">
<id column="ID" name="id">...</id>
<property column="name" name="name"/>
<set cascade="all" name="entitlements">
<key column="GROUP_ID"/>
<one-to-many class="Entitlement"/>
</set>
</class>
<class name="he2.Role" table="ROLE">
<id column="ID" name="id">...</id>
<property column="name" name="name"/>
<set cascade="all" name="entitlements">
<key column="ROLE_ID"/>
<one-to-many class="Entitlement"/>
</set>
</class>