diff --git a/pom.xml b/pom.xml
index 9001e043d4..c0787b50ca 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
> { * {@link Map}'s value type transparently. * * @return + * @deprecated since 2.6 for removal in 3.0. Use {@link #getPersistentEntityTypeInformation()} instead. */ + @Deprecated Iterable extends TypeInformation>> getPersistentEntityTypes(); + /** + * Returns the {@link TypeInformation} if the property references a {@link PersistentEntity}. Will return + * {@literal null} in case it refers to a simple type. Will return {@link Collection}'s component type or the + * {@link Map}'s value type transparently. + * + * @return + * @since 2.6 + */ + Iterable extends TypeInformation>> getPersistentEntityTypeInformation(); + /** * Returns the getter method to access the property value if available. Might return {@literal null} in case there is * no getter method with a return type assignable to the actual property's type. @@ -395,6 +407,19 @@ default boolean hasActualTypeAnnotation(Class extends Annotation> annotationTy @Nullable Class> getAssociationTargetType(); + /** + * Return the type the property refers to in case it's an association, i.e. {@link #isAssociation()} returns + * {@literal true}. That means, that implementations must return a non-{@literal null} value from this method + * in that case. We also recommend to return {@literal null} for non-associations right away to establish symmetry + * between this method and {@link #isAssociation()}. + * + * @return the type the property refers to in case it's an association, i.e. {@link #isAssociation()} returns + * {@literal true}. + * @since 2.6 + */ + @Nullable + TypeInformation> getAssociationTargetTypeInformation(); + /** * Returns a {@link PersistentPropertyAccessor} for the current property's owning value. * diff --git a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java index 6bd3935411..04c5c21d6d 100644 --- a/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java +++ b/src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java @@ -33,7 +33,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; @@ -576,7 +575,7 @@ private void createAndRegisterProperty(Property input) { return; } - property.getPersistentEntityTypes().forEach(it -> { + property.getPersistentEntityTypeInformation().forEach(it -> { if (shouldCreatePersistentEntityFor(it)) { addPersistentEntity(it); 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 fb30c1387f..b7361896b5 100644 --- a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -164,6 +164,15 @@ public TypeInformation> getTypeInformation() { */ @Override public Iterable extends TypeInformation>> getPersistentEntityTypes() { + return getPersistentEntityTypeInformation(); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.mapping.PersistentProperty#getPersistentEntityTypeInformation() + */ + @Override + public Iterable extends TypeInformation>> getPersistentEntityTypeInformation() { if (isMap() || isCollectionLike()) { return entityTypeInformation.get(); @@ -279,11 +288,21 @@ public Association
getAssociation() {
@Override
public Class> getAssociationTargetType() {
- TypeInformation> result = associationTargetType.getNullable();
+ TypeInformation> result = getAssociationTargetTypeInformation();
return result != null ? result.getType() : null;
}
+ /*
+ * (non-Javadoc)
+ * @see org.springframework.data.mapping.PersistentProperty#getAssociationTargetTypeInformation()
+ */
+ @Nullable
+ @Override
+ public TypeInformation> getAssociationTargetTypeInformation() {
+ return associationTargetType.getNullable();
+ }
+
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.PersistentProperty#isCollectionLike()
@@ -356,11 +375,7 @@ public Class> getMapValueType() {
*/
@Override
public Class> getActualType() {
-
- TypeInformation> targetType = associationTargetType.getNullable();
- TypeInformation> result = targetType == null ? information.getRequiredActualType() : targetType;
-
- return result.getType();
+ return getActualTypeInformation().getType();
}
/*
@@ -375,6 +390,12 @@ protected Property getProperty() {
return this.property;
}
+ protected TypeInformation> getActualTypeInformation() {
+
+ TypeInformation> targetType = associationTargetType.getNullable();
+ return targetType == null ? information.getRequiredActualType() : targetType;
+ }
+
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
@@ -415,9 +436,8 @@ public String toString() {
private Set isId = Lazy.of(() -> isAnnotationPresent(Id.class));
private final Lazy !Class.class.equals(it) ? it : getActualType()) //
- .orElseGet(() -> super.getAssociationTargetType());
+ .map(it -> !Class.class.equals(it) ? ClassTypeInformation.from(it) : getActualTypeInformation()) //
+ .orElseGet(() -> super.getAssociationTargetTypeInformation());
});
/**
@@ -295,11 +297,11 @@ public boolean usePropertyAccess() {
/*
* (non-Javadoc)
- * @see org.springframework.data.mapping.PersistentProperty#getAssociationTargetType()
+ * @see org.springframework.data.mapping.model.AbstractPersistentProperty#getAssociationTargetTypeInformation()
*/
@Nullable
@Override
- public Class> getAssociationTargetType() {
+ public TypeInformation> getAssociationTargetTypeInformation() {
return associationTargetType.getNullable();
}
diff --git a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java
index aa0e18b3b0..61967c2a76 100755
--- a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java
+++ b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextIntegrationTests.java
@@ -113,7 +113,7 @@ protected T createPersistentProperty(Property property, BasicPersistentEntity