Search code examples
javaspringspring-data

Spring JpaRepostory delete vs deleteInBatch


What is the difference between delete(...) and deleteInBatch(...) methods in JpaRepostory in Spring ? The second one "deletes items in one SQL statement", but what does it mean from the application/database perspective ? Why exists two different methods with the similar results and when it is better to use one or other ?

EDIT: The same applies also for deleteAll() and deleteAllInBatch() ...


Solution

  • The delete method is going to delete your entity in one operation. The deleteInBatch is going to batch several delete-statements and delete them as 1 operation.

    If you need a lot of delete operations the batch-deletion might be faster.