Composite Aggregation

Model:

component("demo",
  dataElement("City",
    field("districts : DataElement<demo::District>[1..*]")),
  dataElement("District",
    field("city : DataElement<demo::City>")),
  relationship("shared_aggregation",
    end("demo::City::districts"),
    end("demo::District::City")))

CityDetails:

class CityDetails {
  private List<DataRef> districts;
}

DistrictDetails:

class DistrictDetails {
  private DataRef City;
}

DistrictFinderBean:

class DistrictFinderBean {

  SearchResult<DistrictData> findByCityEq(ParameterContext<SearchDetails<DistrictFindByCityEqDetails>> searchParameter) {
    SearchDetails<DistrictFindByCityEqDetails> searchDetails = searchParameter.getValue();
    DistrictFindByCityEqDetails details = searchDetails.getDetails()

    Query query = entityManager.createQuery("select o from District o where o.city.id = :City");
    query.setParameter("City", details.getCity().getId());

    return fetchData(searchDetails, query);
  }
  
}

CityBean (CascadeDelete feature):

class CityBean {

  CrudsResult<Void> delete(ParameterContext<DataRef> targetParameter) {
    try {
      // @anchor:pre-delete:start
      List<DataRef> products = getProducts(targetParameter);
      for (DataRef product : products) {
        CrudsResult<Void> deleteProductResult =  productBean.delete(targetParameter.construct(product));
        if (deleteProductResult.isError()) {
          return deleteProductResult;
        }
      }
      // @anchor:pre-delete:end
      return cityCruds.delete(targetParameter);
    } catch(Exception e) {
      return CrudsResult.error();
    }
  }

}