diff --git a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java index 1769b5052..029f1d997 100644 --- a/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/JpaRepository.java @@ -77,12 +77,28 @@ public interface JpaRepository extends PagingAndSortingRepository, S saveAndFlush(S entity); /** - * Deletes the given entities in a batch which means it will create a single {@link Query}. Assume that we will clear - * the {@link javax.persistence.EntityManager} after the call. + * Deletes the given entities in a batch which means it will create a single {@link Query}. + * + * This kind of operation leaves JPAs first level cache and the database out of sync. + * Consider flushing the `EntityManager` before calling this method. * * @param entities + * @deprecated Use {@link #deleteAllInBatch(Iterable)} instead. */ - void deleteInBatch(Iterable entities); + @Deprecated + default void deleteInBatch(Iterable entities){deleteAllInBatch(entities);} + + /** + * Deletes the given entities in a batch which means it will create a single {@link Query}. + * + * This kind of operation leaves JPAs first level cache and the database out of sync. + * Consider flushing the `EntityManager` before calling this method. + * + * @param entities + * + * @since 3.0 + */ + void deleteAllInBatch(Iterable entities); /** diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index c28498b67..3dfea791b 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -234,7 +234,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation entities) { + public void deleteAllInBatch(Iterable entities) { Assert.notNull(entities, "Entities must not be null!"); diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java index d2ff18140..0cd58c117 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryTests.java @@ -25,7 +25,6 @@ import static org.springframework.data.jpa.domain.Specification.not; import static org.springframework.data.jpa.domain.sample.UserSpecifications.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -259,7 +258,7 @@ public class UserRepositoryTests { long before = repository.count(); - repository.deleteInBatch(asList(firstUser, secondUser)); + repository.deleteAllInBatch(asList(firstUser, secondUser)); assertThat(repository.existsById(firstUser.getId())).isFalse(); assertThat(repository.existsById(secondUser.getId())).isFalse();