File tree 2 files changed +16
-9
lines changed
main/java/org/springframework/data/jpa/repository/support
test/java/org/springframework/data/jpa/repository
2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 15
15
*/
16
16
package org .springframework .data .jpa .repository .support ;
17
17
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 .*;
24
19
25
20
import jakarta .persistence .EntityManager ;
26
21
import jakarta .persistence .LockModeType ;
@@ -524,10 +519,12 @@ public long delete(Specification<T> spec) {
524
519
CriteriaBuilder builder = this .em .getCriteriaBuilder ();
525
520
CriteriaDelete <T > delete = builder .createCriteriaDelete (getDomainClass ());
526
521
527
- Predicate predicate = spec .toPredicate (delete .from (getDomainClass ()), null , builder );
522
+ if (spec != null ) {
523
+ Predicate predicate = spec .toPredicate (delete .from (getDomainClass ()), null , builder );
528
524
529
- if (predicate != null ) {
530
- delete .where (predicate );
525
+ if (predicate != null ) {
526
+ delete .where (predicate );
527
+ }
531
528
}
532
529
533
530
return this .em .createQuery (delete ).executeUpdate ();
Original file line number Diff line number Diff line change @@ -609,6 +609,16 @@ void returnsSamePageIfNoSpecGiven() {
609
609
assertThat (repository .findAll ((Specification <User >) null , pageable )).isEqualTo (repository .findAll (pageable ));
610
610
}
611
611
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
+
612
622
@ Test
613
623
void returnsAllAsPageIfNoPageableIsGiven () {
614
624
You can’t perform that action at this time.
0 commit comments