@@ -379,47 +379,48 @@ public int deleteAttachmentsByObjectIds(
379379 return 0 ;
380380 }
381381
382- // Get the target entity of the composition
382+ // Get the target entity of the composition (this is the SOURCE attachment entity)
383383 CdsAssociationType assocType = (CdsAssociationType ) compositionElement .get ().getType ();
384- String targetEntityName = assocType .getTarget ().getQualifiedName ();
384+ String sourceAttachmentEntityName = assocType .getTarget ().getQualifiedName ();
385385
386386 int deletedCount = 0 ;
387387
388388 // Try deleting from draft table first
389- Optional <CdsEntity > attachmentDraftEntity = model .findEntity (targetEntityName + "_drafts" );
389+ Optional <CdsEntity > attachmentDraftEntity =
390+ model .findEntity (sourceAttachmentEntityName + "_drafts" );
390391 if (attachmentDraftEntity .isPresent ()) {
391392 var deleteQuery =
392393 Delete .from (attachmentDraftEntity .get ())
393394 .where (doc -> doc .get ("objectId" ).in (objectIds .toArray ()));
394395 Result result = persistenceService .run (deleteQuery );
395396 deletedCount += result .rowCount ();
396397 logger .info (
397- "Deleted {} attachment records from draft table '{}' for objectIds: {}" ,
398+ "Deleted {} attachment records from SOURCE draft table '{}' for objectIds: {}" ,
398399 result .rowCount (),
399- targetEntityName + "_drafts" ,
400+ sourceAttachmentEntityName + "_drafts" ,
400401 objectIds );
401402 }
402403
403404 // Try deleting from non-draft table
404- Optional <CdsEntity > attachmentEntity = model .findEntity (targetEntityName );
405+ Optional <CdsEntity > attachmentEntity = model .findEntity (sourceAttachmentEntityName );
405406 if (attachmentEntity .isPresent ()) {
406407 var deleteQuery =
407408 Delete .from (attachmentEntity .get ())
408409 .where (doc -> doc .get ("objectId" ).in (objectIds .toArray ()));
409410 Result result = persistenceService .run (deleteQuery );
410411 deletedCount += result .rowCount ();
411412 logger .info (
412- "Deleted {} attachment records from table '{}' for objectIds: {}" ,
413+ "Deleted {} attachment records from SOURCE table '{}' for objectIds: {}" ,
413414 result .rowCount (),
414- targetEntityName ,
415+ sourceAttachmentEntityName ,
415416 objectIds );
416417 }
417418
418419 if (deletedCount == 0 ) {
419420 logger .warn (
420421 "No attachment metadata found in source entity '{}' for objectIds: {}. This may indicate"
421422 + " the records were already cleaned up." ,
422- targetEntityName ,
423+ sourceAttachmentEntityName ,
423424 objectIds );
424425 }
425426
0 commit comments