From 3a24c6d0d4e557933664783a1e6db0bc3ae846b3 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Tue, 16 Jul 2019 21:09:03 +0200 Subject: [PATCH] =?UTF-8?q?DATAJPA-1535=20-=20Fix=20SpringJpaRepository.de?= =?UTF-8?q?lete(=E2=80=A6)=20for=20repositories=20working=20with=20mapped?= =?UTF-8?q?=20superclasses.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new optimized implementation of SimpleJpaRepository.delete(…) used the Java type registered with the EntityInformation backing the repository, not the concrete type of the entity handed into the method. For mapped superclasses that's problematic as the JPA provider does not know which concrete type to actually look for. We now simply use the type of the actual instance to perform the by id lookup. --- .../support/SimpleJpaRepository.java | 7 ++++-- .../jpa/domain/sample/AbstractMappedType.java | 4 +++- .../MappedTypeRepositoryIntegrationTests.java | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) 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 81dd00f91..73483e89e 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 @@ -179,8 +179,9 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation repository = factory.getRepository(CustomMappedTypeRepository.class); + + ConcreteType1 entity = repository.save(new ConcreteType1()); + + assertThatCode(() -> repository.delete(entity)).doesNotThrowAnyException(); + assertThat(concreteRepository1.findById(entity.getId())).isEmpty(); + } + + private interface CustomMappedTypeRepository extends CrudRepository {} }