File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
main/java/org/springframework/data/jpa/repository/support
test/java/org/springframework/data/jpa/repository Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1515 */
1616package org .springframework .data .jpa .repository .support ;
1717
18- import static org .springframework .data .jpa .repository .query .QueryUtils .COUNT_QUERY_STRING ;
19- import static org .springframework .data .jpa .repository .query .QueryUtils .DELETE_ALL_QUERY_BY_ID_STRING ;
20- import static org .springframework .data .jpa .repository .query .QueryUtils .DELETE_ALL_QUERY_STRING ;
21- import static org .springframework .data .jpa .repository .query .QueryUtils .applyAndBind ;
22- import static org .springframework .data .jpa .repository .query .QueryUtils .getQueryString ;
23- import static org .springframework .data .jpa .repository .query .QueryUtils .toOrders ;
18+ import static org .springframework .data .jpa .repository .query .QueryUtils .*;
2419
2520import jakarta .persistence .EntityManager ;
2621import jakarta .persistence .LockModeType ;
@@ -524,10 +519,12 @@ public long delete(Specification<T> spec) {
524519 CriteriaBuilder builder = this .em .getCriteriaBuilder ();
525520 CriteriaDelete <T > delete = builder .createCriteriaDelete (getDomainClass ());
526521
527- Predicate predicate = spec .toPredicate (delete .from (getDomainClass ()), null , builder );
522+ if (spec != null ) {
523+ Predicate predicate = spec .toPredicate (delete .from (getDomainClass ()), null , builder );
528524
529- if (predicate != null ) {
530- delete .where (predicate );
525+ if (predicate != null ) {
526+ delete .where (predicate );
527+ }
531528 }
532529
533530 return this .em .createQuery (delete ).executeUpdate ();
Original file line number Diff line number Diff line change @@ -609,6 +609,16 @@ void returnsSamePageIfNoSpecGiven() {
609609 assertThat (repository .findAll ((Specification <User >) null , pageable )).isEqualTo (repository .findAll (pageable ));
610610 }
611611
612+ @ Test // GH-2796
613+ void removesAllIfSpecificationIsNull () {
614+
615+ flushTestUsers ();
616+
617+ repository .delete ((Specification <User >) null );
618+
619+ assertThat (repository .count ()).isEqualTo (0L );
620+ }
621+
612622 @ Test
613623 void returnsAllAsPageIfNoPageableIsGiven () {
614624
You can’t perform that action at this time.
0 commit comments