From b9bd0e70e09ce65865f1ead7e7023d850d1a693b Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 10 May 2023 10:44:29 +0200 Subject: [PATCH] =?UTF-8?q?Document=20that=20`JpaSpecificationExecutor.del?= =?UTF-8?q?ete(=E2=80=A6)`=20uses=20`CriteriaDelete`=20and=20hence=20`Casc?= =?UTF-8?q?ades`=20are=20not=20considered.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #2936 --- .../jpa/repository/JpaSpecificationExecutor.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java index 5336ef7b3..bb47389da 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/JpaSpecificationExecutor.java @@ -15,6 +15,10 @@ */ package org.springframework.data.jpa.repository; +import jakarta.persistence.criteria.CriteriaBuilder; +import jakarta.persistence.criteria.CriteriaQuery; +import jakarta.persistence.criteria.Root; + import java.util.List; import java.util.Optional; import java.util.function.Function; @@ -89,6 +93,14 @@ public interface JpaSpecificationExecutor { /** * Deletes by the {@link Specification} and returns the number of rows deleted. + *

+ * This method uses {@link jakarta.persistence.criteria.CriteriaDelete Criteria API bulk delete} that maps directly to + * database delete operations. The persistence context is not synchronized with the result of the bulk delete. + *

+ * Please note that {@link jakarta.persistence.criteria.CriteriaQuery} in, + * {@link Specification#toPredicate(Root, CriteriaQuery, CriteriaBuilder)} will be {@literal null} because + * {@link jakarta.persistence.criteria.CriteriaBuilder#createCriteriaDelete(Class)} does not implement + * {@code CriteriaQuery}. * * @param spec the {@link Specification} to use for the existence check. Must not be {@literal null}. * @return the number of entities deleted.