问题
... always getting exceptions when creating a edge/relation between a vertex and the Neo4j - ReferenceNode.
How to handle something like this?
GraphDatabaseService neoGraphDbService = new EmbeddedGraphDatabase( "d:/testDb" );
System.out.println(neoGraphDbService.getReferenceNode()); // Node[0]
Graph tiGraphDb = new Neo4jGraph(neoGraphDbService);
Vertex referenceNode = tiGraphDb.getVertex(0);
//throws Exception:
//org.neo4j.graphdb.NotFoundException: Node[0]
System.out.println(neoGraphDbService.getReferenceNode());
//referenceNode is null
System.out.println(referenceNode);
Vertex a = tiGraphDb.addVertex(null);
Vertex b = tiGraphDb.addVertex(null);
a.setProperty("name","marko");
b.setProperty("name","peter");
Edge referenceNode_knows_a = tiGraphDb.addEdge(null, referenceNode, a, "knows");
Edge a_knows_b = tiGraphDb.addEdge(null, a, b, "knows");
tiGraphDb.shutdown();
This is my first experience with tinkerpop and i don´t understand what is really happening with the referenceNode, it seems to get lost as soon as i make a tinkerpop connection...
btw. there are no tags yet for tinkerpop, blueprints etc...
回答1:
if you don't specify that the graph is not fresh, blueprints deletes the reference node. Try
Graph tiGraphDb = new Neo4jGraph(neoGraphDbService, false);
To keep Blueprints from meddling with the graph.
/peter
来源:https://stackoverflow.com/questions/8938890/how-to-deal-with-the-neo4j-referencenode-when-using-tinkerpop