@@ -164,17 +164,21 @@ private void processNestedEntityComposition(
164164 return ;
165165 }
166166
167+ // Get the actual key field names from the entity instead of hardcoding "ID"
168+ List <String > keyElementNames = getKeyElementNames (nestedDraftEntity .get ());
169+
167170 Result nestedRecords =
168171 persistenceService .run (
169172 Select .from (nestedDraftEntity .get ())
170- .columns ("ID" )
171173 .where (e -> e .get ("IsActiveEntity" ).eq (false )));
172174
173175 for (Row nestedRecord : nestedRecords ) {
174- Object nestedEntityId = nestedRecord .get ("ID" );
175-
176176 Map <String , Object > nestedEntityKeys = new HashMap <>();
177- nestedEntityKeys .put ("ID" , nestedEntityId );
177+
178+ // Populate the key map with all actual key field names and values
179+ for (String keyName : keyElementNames ) {
180+ nestedEntityKeys .put (keyName , nestedRecord .get (keyName ));
181+ }
178182 nestedEntityKeys .put ("IsActiveEntity" , false );
179183
180184 for (Map .Entry <String , String > entry : nestedAttachmentMapping .entrySet ()) {
@@ -429,6 +433,21 @@ private String getUpIdKey(CdsEntity attachmentDraftEntity) {
429433 return upIdKey ;
430434 }
431435
436+ /**
437+ * Retrieves the key element names from a CdsEntity.
438+ * This method extracts the names of all key fields defined in the entity,
439+ * allowing for dynamic key field handling instead of hardcoding "ID".
440+ *
441+ * @param entity the CdsEntity to extract key element names from
442+ * @return a list of key element names
443+ */
444+ private List <String > getKeyElementNames (CdsEntity entity ) {
445+ return entity .elements ()
446+ .filter (CdsElement ::isKey )
447+ .map (CdsElement ::getName )
448+ .toList ();
449+ }
450+
432451 private void checkAttachmentConstraints (
433452 EventContext context , CdsEntity attachmentDraftEntity , String upID , String upIdKey )
434453 throws ServiceException {
0 commit comments