From e31a96c15b6cedda99105bcee8dda6030eaf035f Mon Sep 17 00:00:00 2001 From: Rishi Kunnath <82925475+rishikunnath2747@users.noreply.github.com> Date: Thu, 27 Nov 2025 15:08:08 +0530 Subject: [PATCH 1/3] potential fix --- .../handler/SDMServiceGenericHandler.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) 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..580a63f6 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,21 @@ 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))); 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 +433,21 @@ 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 { From 2e0f5a2231c51d206f704cda92623544b15d28cf Mon Sep 17 00:00:00 2001 From: Rishi Kunnath <82925475+rishikunnath2747@users.noreply.github.com> Date: Thu, 27 Nov 2025 16:06:08 +0530 Subject: [PATCH 2/3] fix spotless --- .../handler/SDMServiceGenericHandler.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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 580a63f6..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 @@ -169,12 +169,11 @@ private void processNestedEntityComposition( Result nestedRecords = persistenceService.run( - Select.from(nestedDraftEntity.get()) - .where(e -> e.get("IsActiveEntity").eq(false))); + Select.from(nestedDraftEntity.get()).where(e -> e.get("IsActiveEntity").eq(false))); for (Row nestedRecord : nestedRecords) { Map nestedEntityKeys = new HashMap<>(); - + // Populate the key map with all actual key field names and values for (String keyName : keyElementNames) { nestedEntityKeys.put(keyName, nestedRecord.get(keyName)); @@ -434,18 +433,15 @@ private String getUpIdKey(CdsEntity attachmentDraftEntity) { } /** - * 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". + * 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(); + return entity.elements().filter(CdsElement::isKey).map(CdsElement::getName).toList(); } private void checkAttachmentConstraints( From 634d8bd36d51b83dfc6bffac9231fff631a40050 Mon Sep 17 00:00:00 2001 From: Rishi Kunnath <82925475+rishikunnath2747@users.noreply.github.com> Date: Thu, 27 Nov 2025 16:26:24 +0530 Subject: [PATCH 3/3] update pom for testing --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}