From d3cd1ab60a846ed712e0efafec02fcd99b416a21 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 9 Jul 2021 15:09:25 +0200 Subject: [PATCH] Persistent entity type detection now starts with the association target type if available. This causes us to inspect the most concrete type we can find from a property declaration that might be overridden using an annotation. Closes: #2409 Original Pull Request: #2410 --- .../mapping/model/AbstractPersistentProperty.java | 5 ++--- .../AnnotationBasedPersistentPropertyUnitTests.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java index fa3a9e692..b7361896b 100644 --- a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -436,9 +436,8 @@ public abstract class AbstractPersistentProperty

private Set> detectEntityTypes(SimpleTypeHolder simpleTypes) { - TypeInformation typeToStartWith = ASSOCIATION_TYPE != null && ASSOCIATION_TYPE.isAssignableFrom(rawType) - ? information.getComponentType() - : information; + TypeInformation typeToStartWith = getAssociationTargetTypeInformation(); + typeToStartWith = typeToStartWith == null ? information : typeToStartWith; Set> result = detectEntityTypes(typeToStartWith); diff --git a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java index fa6dbe8e9..7b4a52a67 100755 --- a/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/AnnotationBasedPersistentPropertyUnitTests.java @@ -47,6 +47,7 @@ import org.springframework.data.mapping.MappingException; import org.springframework.data.mapping.PersistentProperty; import org.springframework.data.mapping.context.SampleMappingContext; import org.springframework.data.mapping.context.SamplePersistentProperty; +import org.springframework.data.util.ClassTypeInformation; import org.springframework.lang.Nullable; import org.springframework.test.util.ReflectionTestUtils; @@ -318,6 +319,16 @@ public class AnnotationBasedPersistentPropertyUnitTests

it.equals(ClassTypeInformation.from(Sample.class))); + } + @SuppressWarnings("unchecked") private Map, Annotation> getAnnotationCache(SamplePersistentProperty property) { return (Map, Annotation>) ReflectionTestUtils.getField(property, "annotationCache");