4

I am writing some GraphUnit supported integration tests and have noticed odd behavior when I attempt to update the child node an existing relationship points to.

Given an existing relationship with a backing graph that looks like:

(A:ParentNode)-[:SOME_REL {id: 1}]->(B:ChildNode)

If I try to update it by writing code like:

ChildNode newChildNode = new ChildNode();
existingRelationship.setChild(newChild);
RelationshipRepository.save(existingRelationship);

The resulting graph looks like:

(A:ParentNode)
(B:ChildNode)
(C:ChildNode)

But I expect it to look like:

(A:ParentNode)-[:SOME_REL {id: 1}]->(C:ChildNode)

The raw log output I see when I execute the GraphRepository save() includes a DELETE statement in the Cypher query that drops the relationship:

10:32:32.218 [main] DEBUG o.n.o.s.r.SessionRequestHandler - {"statements":[{"statement":"MATCH ()-[_0]->() WHERE id(_0)=0 SET _0+={_0_props}  WITH _0 MATCH ($0)-[_1:`SOME_REL`]->($1) WHERE id($0)=0 AND id($1)=1 AND id(_1)=0 DELETE _1","parameters":{"_0_props":{"doubleProp":1.0}},"resultDataContents":["row"],"includeStats":false}]}
10:32:32.219 [main] INFO  o.n.o.session.request.DefaultRequest - POST http://localhost:7475/db/data/transaction/commit, request: {"statements":[{"statement":"MATCH ()-[_0]->() WHERE id(_0)=0 SET _0+={_0_props}  WITH _0 MATCH ($0)-[_1:`SOME_REL`]->($1) WHERE id($0)=0 AND id($1)=1 AND id(_1)=0 DELETE _1","parameters":{"_0_props":{"doubleProp":1.0}},"resultDataContents":["row"],"includeStats":false}]}

Is this a bug? Or am I not updating an SDN4 relationship entity properly? Do we have to delete relationships and create them from scratch each time we effectively want to do an update?

simonl
  • 1,240
  • 7
  • 19
  • SOME_REL is backed by a relationship entity in SDN 4? And "existingRelationship" refers to this relationship entity or? – Luanne Jul 15 '15 at 16:02
  • Yes, it is backed by a relationship entity and has an associated `GraphRepository`. I've been able to test and prove that my code properly saves the relationship to Neo4j when I am creating it from scratch (using GraphUnit's `printGraph()`) If any specific code snippets would be helpful in troubleshooting, I am very happy to include them! – simonl Jul 15 '15 at 16:05
  • Yes please, if you can share what your relationship entity looks like and the start/end node entities as well that'll be great. Anything that will help me write a test is welcome. Believe you're using the SDN4 snapshot? If so, are you also using the neo4j-ogm 1.1.1-SNAPSHOT? – Luanne Jul 15 '15 at 16:08
  • Hi Luanne, I've created a contrived project at - https://github.com/simon-lam/sdn-4-demo The simplified model I have is in there as well as a test case demonstrating the issue - `SimpleRelationshipRepositoryTest`; the assertion is failing AND the output of `printGraph()` is not what I expected. If it is necessary to take this into JIRA or offline, please let me know! `./gradlew clean test --debug` – simonl Jul 15 '15 at 18:49
  • To answer your other question, no, I am using 1.1.0 of neo4j-ogm. I am hitting `repo.spring.io/libs-snapshot/org/neo4j/neo4j-ogm` and do not see a 1.1.1.SNAPSHOT? – simonl Jul 15 '15 at 21:49
  • Thanks, I'll take a look – Luanne Jul 16 '15 at 02:51
  • For anyone else who wants to look at this exact issue, my contrived repo's master branch has been tagged - https://github.com/simon-lam/sdn-4-demo/releases/tag/DATAGRAPH-706 – simonl Jul 16 '15 at 15:57

1 Answers1

0

Unfortunately, this is a bug. The workaround would be to create a new SimpleRelationship with the new end node, replace the existing one on the parent SimpleNode and save the new RE.

The issue can be tracked here https://jira.spring.io/browse/DATAGRAPH-706

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • Update: this is fixed and will be available in the next SDN 4 release – Luanne Jul 17 '15 at 08:37
  • I've grabbed SDN 4.0.0.RC2 and have retested this and it seems like the issue has been fixed. However, I did notice that the ID on the relationship entity does change though - is that expected behavior? – simonl Aug 24 '15 at 18:55
  • 1
    Yes, it would change because it's a new relationship that's created to the new end node. It's not possible to replace the node of an existing relationship, you have to create a new relationship (therefore, new id assigned), and drop the old one. – Luanne Aug 25 '15 at 04:14