JpaPersistentPropertyImpl.getAssociationTargetType() falls back to actual type for associations
In case a property is an association we now fall back to the property's actual type if there's no explicit association target type.
This commit is contained in:
@@ -224,9 +224,17 @@ class JpaPersistentPropertyImpl extends AnnotationBasedPersistentProperty<JpaPer
|
||||
@Override
|
||||
public Class<?> getAssociationTargetType() {
|
||||
|
||||
return associationTargetType != null //
|
||||
? associationTargetType.getType() //
|
||||
: super.getAssociationTargetType();
|
||||
if (!isAssociation()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (associationTargetType != null) {
|
||||
return associationTargetType.getType();
|
||||
}
|
||||
|
||||
Class<?> targetType = super.getAssociationTargetType();
|
||||
|
||||
return targetType != null ? targetType : getActualType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,6 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
@@ -74,7 +73,9 @@ public class JpaPersistentPropertyImplUnitTests {
|
||||
void considersOneToOneMappedPropertyAnAssociation() {
|
||||
|
||||
JpaPersistentProperty property = entity.getRequiredPersistentProperty("other");
|
||||
|
||||
assertThat(property.isAssociation()).isTrue();
|
||||
assertThat(property.getAssociationTargetType()).isEqualTo(Sample.class);
|
||||
}
|
||||
|
||||
@Test // DATAJPA-376
|
||||
@@ -146,7 +147,7 @@ public class JpaPersistentPropertyImplUnitTests {
|
||||
Iterable<? extends TypeInformation<?>> entityType = property.getPersistentEntityTypes();
|
||||
assertThat(entityType.iterator().hasNext()).isTrue();
|
||||
assertThat(entityType.iterator().next())
|
||||
.isEqualTo((TypeInformation) ClassTypeInformation.from(Implementation.class));
|
||||
.isEqualTo(ClassTypeInformation.from(Implementation.class));
|
||||
}
|
||||
|
||||
@Test // DATAJPA-716
|
||||
|
||||
Reference in New Issue
Block a user