public BusinessServiceEntity toEntity() { BusinessServiceEntity entity = new BusinessServiceEntity(); entity.setName(name); entity.setId(id); entity.setAttributes(attributes); if (reduceFunction != null) { entity.setReductionFunction(reduceFunction); } ipServices.forEach(e -> entity.addIpServiceEdge(e.value, e.mapFunction, e.weight, e.friendlyName)); children.forEach(e -> entity.addChildServiceEdge(e.value, e.mapFunction, e.weight)); reductionKeys.forEach(e -> entity.addReductionKeyEdge(e.value, e.mapFunction, e.weight, e.friendlyName)); return entity; }
@Override public void setReduceFunction(final BusinessService businessService, final ReductionFunction reductionFunction) { // This is a workaround for a hibernate bug which does not remove // orphan elements if the element is replaced using the setter. See: // https://hibernate.atlassian.net/browse/HHH-6484 final BusinessServiceEntity entity = this.getBusinessServiceEntity(businessService); final AbstractReductionFunctionEntity prevReduceFunctionEntity = entity.getReductionFunction(); if (prevReduceFunctionEntity != null && prevReduceFunctionEntity.getId() != null) { this.reductionFunctionDao.delete(prevReduceFunctionEntity); } final AbstractReductionFunctionEntity reduceFunctionEntity = new ReduceFunctionMapper().toPersistenceFunction(reductionFunction); entity.setReductionFunction(reduceFunctionEntity); }