Skip to content

Commit 3c8c2a3

Browse files
committed
GH-2599 - Fix bug on save with updated and new relationship properties.
Closes #2599
1 parent 7521b0c commit 3c8c2a3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,8 @@ private <T> T processNestedRelations(
938938
neo4jClient.query(renderer.render(statementHolder.getStatement()))
939939
.bindAll(statementHolder.getProperties())
940940
.run();
941-
} else if (!newRelatedValuesToStore.isEmpty()) {
941+
}
942+
if (!newRelatedValuesToStore.isEmpty()) {
942943
CreateRelationshipStatementHolder statementHolder = neo4jMappingContext.createStatementForImperativeRelationshipsWithPropertiesBatch(true,
943944
sourceEntity, relationshipDescription, newRelatedValuesToStore, newRelationshipPropertiesRows);
944945

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

+20
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,26 @@ void findAndMapMultipleLevelRelationshipProperties(
16661666
assertThat(entity.getRelationshipA().getEntityA().getRelationshipB().getEntityB()).isNotNull();
16671667
}
16681668

1669+
@Test
1670+
void updateAndCreateRelationshipProperties(@Autowired HobbyWithRelationshipWithPropertiesRepository repository) {
1671+
1672+
long hobbyId = doWithSession(
1673+
session -> session.run("CREATE (n:AltPerson{name:'Freddie'}), (n)-[l1:LIKES {rating: 5}]->(h1:AltHobby{name:'Music'}) RETURN n, h1").single().get("h1").asNode().id());
1674+
1675+
AltHobby hobby = repository.findById(hobbyId).get();
1676+
assertThat(hobby.getName()).isEqualTo("Music");
1677+
assertThat(hobby.getLikedBy()).hasSize(1);
1678+
1679+
AltLikedByPersonRelationship liked = new AltLikedByPersonRelationship();
1680+
liked.setAltPerson(new AltPerson("SomethingElse"));
1681+
hobby.getLikedBy().add(liked);
1682+
1683+
repository.save(hobby);
1684+
1685+
AltHobby savedHobby = repository.findById(hobbyId).get();
1686+
assertThat(savedHobby.getLikedBy()).hasSize(2);
1687+
1688+
}
16691689
}
16701690

16711691
@Nested

0 commit comments

Comments
 (0)