How to deal with the Neo4j ReferenceNode when using Tinkerpop

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 12:03:23

问题


... 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!