cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

SDN 6 bidirectional relationships generate redundant statements

In Spring Data Neo4j 6.0.2 (SNAPSHOT), it seems that bidrectional relationships generate unnecessary statements.

Let's say we have:

@Node
public class EntityA {
    @Id @GeneratedValue(UUIDStringGenerator.class)
    public String id;

    @Relationship("HAS_ENTITY_B")
    public EntityB entityB;
}

@Node
public class EntityB {
    @Id @GeneratedValue(UUIDStringGenerator.class)
    public String id;

    @Relationship(value = "HAS_ENTITY_B", direction = Relationship.Direction.INCOMING)
    public EntityA entityA;
} 

The following code

var a = new EntityA();
neo4jTemplate.save(a);

results in the following statement, which is correct

MERGE (n:`EntityA` {id: $__id__}) SET n = $__properties__ RETURN id(n)

But then if we add a relationship between the two entities:

var b = new EntityB();
a.entityB = b;
b.entityA = a;
neo4jTemplate.save(b);

It seems the relationship is created, then deleted, the created again, which doesn't make sense to me

MERGE (n:`EntityB` {id: $__id__}) SET n = $__properties__ RETURN id(n)

MERGE (n:`EntityA` {id: $__id__}) SET n = $__properties__ RETURN id(n)

MATCH (startNode:`EntityB`) WHERE startNode.id = $fromId MATCH (endNode) WHERE id(endNode) = 804 MERGE (startNode)<-[:`HAS_ENTITY_B`]-(endNode)

MATCH (startNode:`EntityA`)-[rel:`HAS_ENTITY_B`]->(:`EntityB`) WHERE startNode.id = $fromId DELETE rel

MERGE (n:`EntityB` {id: $__id__}) SET n = $__properties__ RETURN id(n)

MATCH (startNode:`EntityA`) WHERE startNode.id = $fromId MATCH (endNode) WHERE id(endNode) = 809 MERGE (startNode)-[:`HAS_ENTITY_B`]->(endNode)

Is this a bug, or can sonmeone explain what is going on? Thanks!

1 REPLY 1

This looks like something we have to investigate. There should be a mechanism in place that avoids those creation.
I created an issue for this to track https://jira.spring.io/browse/DATAGRAPH-1442