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
This commit is contained in:
committed by
Christoph Strobl
parent
e565c11dcc
commit
d3cd1ab60a
@@ -436,9 +436,8 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
|
||||
|
||||
private Set<TypeInformation<?>> detectEntityTypes(SimpleTypeHolder simpleTypes) {
|
||||
|
||||
TypeInformation<?> typeToStartWith = ASSOCIATION_TYPE != null && ASSOCIATION_TYPE.isAssignableFrom(rawType)
|
||||
? information.getComponentType()
|
||||
: information;
|
||||
TypeInformation<?> typeToStartWith = getAssociationTargetTypeInformation();
|
||||
typeToStartWith = typeToStartWith == null ? information : typeToStartWith;
|
||||
|
||||
Set<TypeInformation<?>> result = detectEntityTypes(typeToStartWith);
|
||||
|
||||
|
||||
@@ -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<P extends AnnotationBase
|
||||
assertThat(property.getAssociationTargetType()).isEqualTo(JMoleculesAggregate.class);
|
||||
}
|
||||
|
||||
@Test // GH-2409
|
||||
void exposesAssociationTargetClassAsPersistentEntityType() {
|
||||
|
||||
SamplePersistentProperty property = getProperty(WithReferences.class, "toSample");
|
||||
|
||||
assertThat(property.getPersistentEntityTypeInformation()) //
|
||||
.isNotEmpty() //
|
||||
.allMatch(it -> it.equals(ClassTypeInformation.from(Sample.class)));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<Class<? extends Annotation>, Annotation> getAnnotationCache(SamplePersistentProperty property) {
|
||||
return (Map<Class<? extends Annotation>, Annotation>) ReflectionTestUtils.getField(property, "annotationCache");
|
||||
|
||||
Reference in New Issue
Block a user