Question

I am using an embedded graph database as part of a java application. Suppose that I carry out some type of cypher query, and return an ExecutionResult which contains a collection of nodes.

These nodes may be assumed to form a connected graph.

Each of these nodes has some relationships, which I can access using node.getRelationships(Direction.OUTGOING). My question is, if the target of one of these relationships already occurs in the Execution result (i.e. the relationship is part of the query template), is it guaranteed that Relationship.getEndPoint == Node X.

I suppose that what I am really asking is, when a transaction in Neo4j returns a node, does it return just the one object, and different queries will just keep returning references to that one object, or does it keep producing new objects which happen to refer to the same data point? Since Node doesn't override the equalsTo method, I have been assuming the former, but I was hoping someone could tell me.

Was it helpful?

Solution

Nodes are not reference-equals. You'll only get NodeProxy objects which are created on the fly in different operations.

But the equals()-method does id-equality so you should use that.

n1.equals(n2)

or if you keep the node id around use

n1.getId() == n2.getId()

OTHER TIPS

See when you create a node neo4j internally assigns it a node-id. All the relationships you create will have reference to the start node id and end node id.

For checking do this

First create a node and save its node id by calling method node.getId()

Now create a relationship to it from another node. And call your relationship.getEndNode().getId() .

You will see the node-ids are same.

It sounds like your asking - does Neo 'out of the box' give concurrency control of database entities, like n-hibernate or entity framework does for SQL. The answer is no! You will have to manage it yourself. If you do delelop it though, could make you a few bob

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top