salvador
salvador

Reputation: 1089

Why Neo4j creates Node[0]?

I am trying the following simple example using the Neo4j Java api:

public void createDB(String datasetRoot) {
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("data/Neo4jTest1");
registerShutdownHook(graphDb);

Transaction tx = graphDb.beginTx();
try {
    // Database operations go here
    Node firstNode = graphDb.createNode();
    firstNode.setProperty("nodeId", "1");
    Node secondNode = graphDb.createNode();
    secondNode.setProperty("nodeId", "2");

    Relationship relationship = firstNode.createRelationshipTo(secondNode, RelTypes.SIMILAR);

    tx.success();
}
finally {
    tx.finish();
}

When I am trying to print all the created nodes I notice the a Node[0] with no property has generated. Why is this happening?

Upvotes: 2

Views: 142

Answers (1)

Ramesh Kotha
Ramesh Kotha

Reputation: 8322

This is called Reference Node in Neo4j. And it is default behavior of neo4j. It will create a a node with node id 0 and with no properties.

Please check this https://github.com/neo4j/neo4j/issues/175

Upvotes: 3

Related Questions