From 879f3b317de86c09d98316a7dae35f78353fe2f2 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 18 Jul 2019 15:02:25 +0200 Subject: [PATCH] =?UTF-8?q?DATAJPA-1535=20-=20Make=20sure=20we=20resolve?= =?UTF-8?q?=20proxy=20types=20in=20optimized=20SimpleJpaRepository.delete(?= =?UTF-8?q?=E2=80=A6).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We now properly lookup the actual user type in case proxy instances are handed into SimpleJpaRepository.delete(…) which might occur if other aggregates hold a direct reference to the one eventually handed into delete(…). --- .../data/jpa/repository/support/SimpleJpaRepository.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 73483e89e..329c8cd11 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -53,6 +53,7 @@ import org.springframework.data.jpa.repository.query.EscapeCharacter; import org.springframework.data.jpa.repository.query.QueryUtils; import org.springframework.data.jpa.repository.support.QueryHints.NoHints; import org.springframework.data.repository.support.PageableExecutionUtils; +import org.springframework.data.util.ProxyUtils; import org.springframework.lang.Nullable; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; @@ -190,7 +191,9 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation type = ProxyUtils.getUserClass(entity); + + T existing = (T) em.find(type, entityInformation.getId(entity)); // if the entity to be deleted doesn't exist, delete is a NOOP if (existing == null) {