diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java index cef7b7f99..660e668e0 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/service/LibraryProcessingService.java @@ -111,6 +111,8 @@ public class LibraryProcessingService { @Transactional protected void deleteRemovedBooks(List removedBookEntities) { if (!removedBookEntities.isEmpty()) { + entityManager.flush(); + entityManager.clear(); Set bookIds = removedBookEntities.stream().map(BookEntity::getId).collect(Collectors.toSet()); bookRepository.deleteByIdIn(bookIds); notificationService.sendMessage(Topic.BOOKS_REMOVE, bookIds);