Skip to content

Skip entity detection for converted properties #2870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>7.3.0-SNAPSHOT</version>
<version>7.3.0-GH-2869-SNAPSHOT</version>

<name>Spring Data Neo4j</name>
<description>Next generation Object-Graph-Mapping for Spring Data.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,7 +210,13 @@ public boolean isAssociation() {

@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
Expand All @@ -219,7 +226,7 @@ public boolean isEntityWithRelationshipProperties() {

@Override
public Neo4jPersistentPropertyConverter<?> getOptionalConverter() {
return customConversion.getOptional()
return isEntity() ? null : customConversion.getOptional()
.map(Neo4jPersistentPropertyConverter.class::cast)
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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;
Expand All @@ -57,6 +58,16 @@ void persistentEntityCreationWorksForCorrectEntity() {
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 {

Expand Down Expand Up @@ -730,4 +741,14 @@ static class WithAnnotatedProperties {
@Property(readOnly = false)
private String writableProperty;
}

static class WithConvertedProperty {

@ConvertWith
IWillBeConverted converted;
}

static class IWillBeConverted {

}
}