6 Replies Latest reply on May 19, 2007 4:54 AM by Tom Baeyens

    Identity module cascading delete of doom

    David Lloyd Master

      In User.hbm.xml, we have this collection:

      <set name="memberships" cascade="all">
       <key column="USER_" />
       <one-to-many class="org.jbpm.identity.Membership" />
      </set>
      


      In Group.hbm.xml, the same collection is referenced:

      <set name="memberships" cascade="all">
       <key column="GROUP_" />
       <one-to-many class="org.jbpm.identity.Membership" />
      </set>
      


      and Membership.hbm.xml has:

       <many-to-one name="user" column="USER_" cascade="all" foreign-key="FK_ID_MEMSHIP_USR"/>
       <many-to-one name="group" column="GROUP_" cascade="all" foreign-key="FK_ID_MEMSHIP_GRP"/>
      


      This is a problem because if you delete a user or a group, it cascades madly through all the users and groups that are related by membership.

      I think that the desired behavior would be that if a User is deleted, then all the corresponding memberships should be deleted but NOT the groups. Likewise, if a Group is deleted, the memberships for that Group should also be deleted, but not the Users.

      I think (pending some testing) that the way to achieve this is to remove the cascade="all" from the "many-to-one" tags in Membership.

      Anyone have any objection or thoughts on this?