Deleting Associated Data

When entities form parent-child relationships, if the parent entity is deleted, all its child entities are also deleted. When an entity that participates in a relationship is deleted, by default, the relationships for that entity are deleted but the related entities are not.

For example, suppose the details of all the people in a household have been collected and Person entities created and the relationships between the people in the household have also been captured and Relationship entities created. If the user chooses to remove a person, the relationships that person participates in will also be removed but none of the other people in the household will be removed.

This default behavior also applies to the income/employment example. If the user chooses to remove an income, any EmploymentRelationships for the income will be removed but none of the Employment entities will be removed.

It is possible to change the default behavior when deleting associated entities so that any entities related to the entity being removed will also be removed.

To change the default behavior, an annotation containing a documentation element may be added to the definition of a relationship entity in the DS schema. A documentation element containing the text "@curam.ieg.cascading.delete=true" indicates that related entities should be deleted when the relationship is deleted.

Figure 1. Cascading Deletes Schema
<xsd:element name="EmploymentRelationship">
  <xsd:annotation>
    <xsd:documentation>@curam.ieg.cascading.delete=true
    </xsd:documentation>
  </xsd:annotation>
  <xsd:complexType>
    <xsd:attribute name="employmentID" type="d:SVR_KEY" />
  </xsd:complexType>
</xsd:element>

In the Income/Employment example, if curam.ieg.cascading.delete is set to true for the EmploymentRelationship when an Income entity is removed any associated Employment entity will also be removed. Removing the Employment entities in this way does not cause other Income entities to the removed.