Skip entity detection for converted properties.
DefaultNeo4jPersistentProperty.isEntity() and getPersistentEntityTypeInformation() now return that the property does not map to an entity if a converter is registered. Closes #2869
This commit is contained in:
committed by
Gerrit Meier
parent
79aacaa181
commit
caddcb6362
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.neo4j.core.mapping;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
@@ -209,7 +210,13 @@ final class DefaultNeo4jPersistentProperty extends AnnotationBasedPersistentProp
|
||||
|
||||
@Override
|
||||
public boolean isEntity() {
|
||||
return super.isEntity() && !isWritableProperty.get();
|
||||
return super.isEntity() && !isWritableProperty.get() && !this.isAnnotationPresent(ConvertWith.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<? extends TypeInformation<?>> getPersistentEntityTypeInformation() {
|
||||
return this.isAnnotationPresent(ConvertWith.class) ? Collections.emptyList()
|
||||
: super.getPersistentEntityTypeInformation();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -219,7 +226,7 @@ final class DefaultNeo4jPersistentProperty extends AnnotationBasedPersistentProp
|
||||
|
||||
@Override
|
||||
public Neo4jPersistentPropertyConverter<?> getOptionalConverter() {
|
||||
return customConversion.getOptional()
|
||||
return isEntity() ? null : customConversion.getOptional()
|
||||
.map(Neo4jPersistentPropertyConverter.class::cast)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.annotation.ReadOnlyProperty;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.neo4j.core.convert.ConvertWith;
|
||||
import org.springframework.data.neo4j.core.schema.DynamicLabels;
|
||||
import org.springframework.data.neo4j.core.schema.GeneratedValue;
|
||||
import org.springframework.data.neo4j.core.schema.Id;
|
||||
@@ -57,6 +58,16 @@ class DefaultNeo4jPersistentEntityTest {
|
||||
neo4jMappingContext.getPersistentEntity(CorrectEntity2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipsEntityTypeDetectionForConvertedProperties() {
|
||||
|
||||
Neo4jPersistentEntity<?> entity = new Neo4jMappingContext().getRequiredPersistentEntity(WithConvertedProperty.class);
|
||||
Neo4jPersistentProperty property = entity.getRequiredPersistentProperty("converted");
|
||||
|
||||
assertThat(property.isEntity()).isFalse();
|
||||
assertThat(property.getPersistentEntityTypeInformation()).isEmpty();
|
||||
}
|
||||
|
||||
@Nested
|
||||
class ReadOnlyProperties {
|
||||
|
||||
@@ -730,4 +741,14 @@ class DefaultNeo4jPersistentEntityTest {
|
||||
@Property(readOnly = false)
|
||||
private String writableProperty;
|
||||
}
|
||||
|
||||
static class WithConvertedProperty {
|
||||
|
||||
@ConvertWith
|
||||
IWillBeConverted converted;
|
||||
}
|
||||
|
||||
static class IWillBeConverted {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user