@@ -15,12 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jpa.repository.support;
|
||||
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.COUNT_QUERY_STRING;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.DELETE_ALL_QUERY_BY_ID_STRING;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.DELETE_ALL_QUERY_STRING;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.applyAndBind;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.getQueryString;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.toOrders;
|
||||
import static org.springframework.data.jpa.repository.query.QueryUtils.*;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.LockModeType;
|
||||
@@ -524,10 +519,12 @@ public class SimpleJpaRepository<T, ID> implements JpaRepositoryImplementation<T
|
||||
CriteriaBuilder builder = this.em.getCriteriaBuilder();
|
||||
CriteriaDelete<T> delete = builder.createCriteriaDelete(getDomainClass());
|
||||
|
||||
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);
|
||||
if (spec != null) {
|
||||
Predicate predicate = spec.toPredicate(delete.from(getDomainClass()), null, builder);
|
||||
|
||||
if (predicate != null) {
|
||||
delete.where(predicate);
|
||||
if (predicate != null) {
|
||||
delete.where(predicate);
|
||||
}
|
||||
}
|
||||
|
||||
return this.em.createQuery(delete).executeUpdate();
|
||||
|
||||
@@ -609,6 +609,16 @@ class UserRepositoryTests {
|
||||
assertThat(repository.findAll((Specification<User>) null, pageable)).isEqualTo(repository.findAll(pageable));
|
||||
}
|
||||
|
||||
@Test // GH-2796
|
||||
void removesAllIfSpecificationIsNull() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
repository.delete((Specification<User>) null);
|
||||
|
||||
assertThat(repository.count()).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsAllAsPageIfNoPageableIsGiven() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user