Home > Blockchain >  Accuracy of results for spring.io guide accessing-data-neo4j?
Accuracy of results for spring.io guide accessing-data-neo4j?

Time:07-01

I ran a spring.io guide for neo4j, and it did not return expected results.

For a sanity check, I was not sure where else to go for this. Running the spring guide with this documentation does not return results as expected. The docs state results will be similar to:

Before linking up with Neo4j...
    Greg's teammates => []
    Roy's teammates => []
    Craig's teammates => []

Lookup each person by name...
    Greg's teammates => [Roy, Craig]
    Roy's teammates => [Greg, Craig]
    Craig's teammates => [Roy, Greg]

However, in two instances, each on a different system, I got back the following:

Before linking up with Neo4j...
    Greg's teammates => []
    Roy's teammates => []
    Craig's teammates => []

Lookup each person by name...
    Greg's teammates => [Roy, Craig]
    Roy's teammates => [Craig]
    Craig's teammates => []

Yes, they are similar but not the same. Can someone confirm their own results for the same guide?

CodePudding user response:

I checked the guide and it seems that the expected output is wrong. My assumption is that it is a left-over of the old Spring Data Neo4j / Neo4j-OGM behaviour when there was a bi-directional relationship definition (also judging from the comment above the relationship in the Person class).

For completeness I add the relationship creation code here:

greg = personRepository.findByName(greg.getName());
greg.worksWith(roy);
greg.worksWith(craig);
personRepository.save(greg);

roy = personRepository.findByName(roy.getName());
roy.worksWith(craig);
// We already know that roy works with greg
personRepository.save(roy);

// We already know craig works with roy and greg

Also looking at the comments there, I would definitely say that the assumptions are just plain wrong. The worksWith function only adds the relationship on the calling object and not the opposite.

So either the guide has to change the behaviour of the worksWith function or the expected output and the comments needs to get changed.

tl;dr; Your output is correct for me compared with the application's code.

  • Related