Hi,
I’ve been struggling to model a recursive aggregate in recent days .
Let’s say Organization is aggregate and it has sub organizations with the same structure . When adding a new organization, the parent should know the new child . When deleting an organization, all of the children should be deleted.
Basically, there may be 2 options to model the aggregate:
------------Option 1----------------
@Aggregate
public class Organization {
@AggregateIdentifier @EntityId private String organizationId;
@AggregateMember private List<Organization> subOrganizations;
}
Question: Deleting the Aggregate will delete it’s member automatically I guess, but which ones are aggregate and which ones are member in a hierarchical relationship ? Is “Sub Organization C” aggregate or member in the following example ?
Organization root [Aggregate]
- Sub Organization A [Member]
- Sub Organization B [Member]
- Sub Organization C [Member]
Or,
Organization root [Aggregate]
- Sub Organization A [Member]
- Sub Organization B [Member]
- Sub Organization C [Aggregate]
------------Option 2----------------
@Aggregate
public class Organization {
@AggregateIdentifier private String organizationId;
private String parentOranizationId;