Using SDN 6.
When creating two nodes with multiple relationships of the same type, only the last relationship, in the list of relationships, survives the save method of the neo4Tempate. According to the cypher debug it also seems like, SDN during the save deletes all existing relationships, which also is weird.
Code:
@Node
@Data @With @AllArgsConstructor @NoArgsConstructor
public class Person {
@Id @GeneratedValue
private Long Id;
private String name;
@Relationship(type = "CALLS", direction = Direction.OUTGOING)
private List<Calls> calls;
}
@RelationshipProperties
@Data @With @AllArgsConstructor @RequiredArgsConstructor
public class Calls {
@Id @GeneratedValue
private Long id;
@TargetNode
private final Person target;
private String day;
}
@Test
public void create_persons_calls() {
Person p1 = new Person().withName("Person-1");
Person p2 = new Person().withName("Person-2");
p1.setCalls(List.of(new Calls(p2).withDay("monday")
,new Calls(p2).withDay("tuesday ")
,new Calls(p2).withDay("wednesday")
));
this.neoTemplate.save(p1);
}
The testcase succeeds but only leaves these these nodes and relationships in Neo4j database:
Looking at the debug output a sequence of statements appear. In between a few DELETE statements, which apparently deletes the relationships just created, but why???
MATCH (startNode)-[rel:`CALLS`]->(:`Person`) WHERE id(startNode) = $fromId DELETE rel
Its odd, because the the CALLS are all unique. Creating the same relationships manually is allowed in Neo4J:
CREATE (s:Person{name: "Person-1"})
CREATE (t:Person{name: "Person-2"})
CREATE (s)-[:CALLS]->(t)
CREATE (s)-[:CALLS]->(t)
CREATE (s)-[:CALLS]->(t)
And will create this:
As a workaround, it's actually possible to create multiple CALLS manually by creating a Neo4JRepository and add a "addCalls" method with a @Query annotation with an appropriate cypher query. But this makes object mapping in SDN useless and I'd like to create the relationships using the object model
Why isn't it possible to create multiple relationships of the same type between two nodes using the object model and the save methods of the neo4jTemplate, according to the example in the top?
I'm looking forward for an explanation as I need a fix for this.