Skip to content

Commit 26e07c5

Browse files
committed
DATAGRAPH-1396 - Fix saving of scalar RelationshipProperties.
1 parent 930f8fc commit 26e07c5

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/main/java/org/springframework/data/neo4j/core/mapping/NestedRelationshipContext.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,20 @@ public static NestedRelationshipContext of(Association<Neo4jPersistentProperty>
146146
}
147147
value = relationshipProperties;
148148
} else {
149-
List<MappingSupport.RelationshipPropertiesWithEntityHolder> relationshipProperties = new ArrayList<>();
150-
for (Object relationshipProperty : ((Collection<Object>) value)) {
149+
if (inverse.isCollectionLike()) {
150+
List<MappingSupport.RelationshipPropertiesWithEntityHolder> relationshipProperties = new ArrayList<>();
151+
for (Object relationshipProperty : ((Collection<Object>) value)) {
151152

152-
MappingSupport.RelationshipPropertiesWithEntityHolder oneOfThem =
153-
new MappingSupport.RelationshipPropertiesWithEntityHolder(relationshipProperty,
154-
getTargetNode(relationshipPropertiesEntity, relationshipProperty));
155-
relationshipProperties.add(oneOfThem);
153+
MappingSupport.RelationshipPropertiesWithEntityHolder oneOfThem =
154+
new MappingSupport.RelationshipPropertiesWithEntityHolder(relationshipProperty,
155+
getTargetNode(relationshipPropertiesEntity, relationshipProperty));
156+
relationshipProperties.add(oneOfThem);
157+
}
158+
value = relationshipProperties;
159+
} else {
160+
value = new MappingSupport.RelationshipPropertiesWithEntityHolder(value,
161+
getTargetNode(relationshipPropertiesEntity, value));
156162
}
157-
value = relationshipProperties;
158163
}
159164
}
160165

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,12 @@ void saveEntityWithRelationshipWithProperties(
10441044
hobbies.add(rel2);
10451045
person.setHobbies(hobbies);
10461046

1047+
WorksInClubRelationship worksInClub = new WorksInClubRelationship(2002);
1048+
Club club = new Club();
1049+
club.setName("BlubbClub");
1050+
worksInClub.setClub(club);
1051+
person.setClub(worksInClub);
1052+
10471053
// when
10481054
PersonWithRelationshipWithProperties shouldBeDifferentPerson = repository.save(person);
10491055

@@ -3052,6 +3058,8 @@ interface RelationshipRepository extends Neo4jRepository<PersonWithRelationship,
30523058

30533059
PersonWithRelationship findByPetsName(String petName);
30543060

3061+
PersonWithRelationship findByName(String name);
3062+
30553063
PersonWithRelationship findByHobbiesNameOrPetsName(String hobbyName, String petName);
30563064

30573065
PersonWithRelationship findByHobbiesNameAndPetsName(String hobbyName, String petName);

src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveRepositoryIT.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.springframework.data.neo4j.integration.shared.AltLikedByPersonRelationship;
2323
import org.springframework.data.neo4j.integration.shared.AltPerson;
24+
import org.springframework.data.neo4j.integration.shared.WorksInClubRelationship;
2425
import reactor.core.publisher.Flux;
2526
import reactor.core.publisher.Mono;
2627
import reactor.test.StepVerifier;
@@ -1055,11 +1056,17 @@ void saveEntityWithRelationshipWithProperties(
10551056
List<LikesHobbyRelationship> hobbies = new ArrayList<>();
10561057
hobbies.add(rel1);
10571058
hobbies.add(rel2);
1058-
PersonWithRelationshipWithProperties clonePerson = new PersonWithRelationshipWithProperties("Freddie clone");
1059-
clonePerson.setHobbies(hobbies);
1059+
PersonWithRelationshipWithProperties person = new PersonWithRelationshipWithProperties("Freddie clone");
1060+
person.setHobbies(hobbies);
1061+
1062+
WorksInClubRelationship worksInClub = new WorksInClubRelationship(2002);
1063+
Club club = new Club();
1064+
club.setName("BlubbClub");
1065+
worksInClub.setClub(club);
1066+
person.setClub(worksInClub);
10601067

10611068
// when
1062-
Mono<PersonWithRelationshipWithProperties> operationUnderTest = repository.save(clonePerson);
1069+
Mono<PersonWithRelationshipWithProperties> operationUnderTest = repository.save(person);
10631070

10641071
// then
10651072
List<PersonWithRelationshipWithProperties> shouldBeDifferentPersons = new ArrayList<>();
@@ -1071,7 +1078,7 @@ void saveEntityWithRelationshipWithProperties(
10711078
assertThat(shouldBeDifferentPersons).size().isEqualTo(1);
10721079

10731080
PersonWithRelationshipWithProperties shouldBeDifferentPerson = shouldBeDifferentPersons.get(0);
1074-
assertThat(shouldBeDifferentPerson).isNotNull().isEqualToComparingOnlyGivenFields(clonePerson, "hobbies");
1081+
assertThat(shouldBeDifferentPerson).isNotNull().isEqualToComparingOnlyGivenFields(person, "hobbies");
10751082
assertThat(shouldBeDifferentPerson.getName()).isEqualToIgnoringCase("Freddie clone");
10761083

10771084
// check content of db

0 commit comments

Comments
 (0)