Skip to content

Commit d2fa85a

Browse files
committed
Document that JpaSpecificationExecutor.delete(…) uses CriteriaDelete and hence Cascades are not considered.
Closes #2936
1 parent b3cb1f7 commit d2fa85a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java

+12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
*/
1616
package org.springframework.data.jpa.repository;
1717

18+
import jakarta.persistence.criteria.CriteriaBuilder;
19+
import jakarta.persistence.criteria.CriteriaQuery;
20+
import jakarta.persistence.criteria.Root;
21+
1822
import java.util.List;
1923
import java.util.Optional;
2024
import java.util.function.Function;
@@ -89,6 +93,14 @@ public interface JpaSpecificationExecutor<T> {
8993

9094
/**
9195
* Deletes by the {@link Specification} and returns the number of rows deleted.
96+
* <p>
97+
* This method uses {@link jakarta.persistence.criteria.CriteriaDelete Criteria API bulk delete} that maps directly to
98+
* database delete operations. The persistence context is not synchronized with the result of the bulk delete.
99+
* <p>
100+
* Please note that {@link jakarta.persistence.criteria.CriteriaQuery} in,
101+
* {@link Specification#toPredicate(Root, CriteriaQuery, CriteriaBuilder)} will be {@literal null} because
102+
* {@link jakarta.persistence.criteria.CriteriaBuilder#createCriteriaDelete(Class)} does not implement
103+
* {@code CriteriaQuery}.
92104
*
93105
* @param spec the {@link Specification} to use for the existence check, must not be {@literal null}.
94106
* @return the number of entities deleted.

0 commit comments

Comments
 (0)