diff --git a/pom.xml b/pom.xml index fdec1f3c..d5a84cfb 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ - 1.6.2-SNAPSHOT + 1.0.0-RC1 17 ${java.version} ${java.version} diff --git a/sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMServiceGenericHandler.java b/sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMServiceGenericHandler.java index 1bec4714..bfde1f41 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMServiceGenericHandler.java +++ b/sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMServiceGenericHandler.java @@ -164,17 +164,20 @@ private void processNestedEntityComposition( return; } + // Get the actual key field names from the entity instead of hardcoding "ID" + List keyElementNames = getKeyElementNames(nestedDraftEntity.get()); + Result nestedRecords = persistenceService.run( - Select.from(nestedDraftEntity.get()) - .columns("ID") - .where(e -> e.get("IsActiveEntity").eq(false))); + Select.from(nestedDraftEntity.get()).where(e -> e.get("IsActiveEntity").eq(false))); for (Row nestedRecord : nestedRecords) { - Object nestedEntityId = nestedRecord.get("ID"); - Map nestedEntityKeys = new HashMap<>(); - nestedEntityKeys.put("ID", nestedEntityId); + + // Populate the key map with all actual key field names and values + for (String keyName : keyElementNames) { + nestedEntityKeys.put(keyName, nestedRecord.get(keyName)); + } nestedEntityKeys.put("IsActiveEntity", false); for (Map.Entry entry : nestedAttachmentMapping.entrySet()) { @@ -429,6 +432,18 @@ private String getUpIdKey(CdsEntity attachmentDraftEntity) { return upIdKey; } + /** + * Retrieves the key element names from a CdsEntity. This method extracts the names of all key + * fields defined in the entity, allowing for dynamic key field handling instead of hardcoding + * "ID". + * + * @param entity the CdsEntity to extract key element names from + * @return a list of key element names + */ + private List getKeyElementNames(CdsEntity entity) { + return entity.elements().filter(CdsElement::isKey).map(CdsElement::getName).toList(); + } + private void checkAttachmentConstraints( EventContext context, CdsEntity attachmentDraftEntity, String upID, String upIdKey) throws ServiceException {