Question

I am implementing traversal framework using neo4j java-rest-binding project. Code is as follows:

RestAPI db = new RestAPIFacade("http://localhost:7474/db/data");
RestNode n21 = db.getNodeById(21);
Map<String,Object> traversalDesc = new HashMap<String, Object>();
traversalDesc.put("order", "breadth_first");
traversalDesc.put("uniqueness", "node_global");
traversalDesc.put("uniqueness", "relationship_global");
traversalDesc.put("returnType", "fullpath");
traversalDesc.put("max_depth", 2);
RestTraverser traverser = db.traverse(n21, traversalDesc);
Iterable<Node> nodes = traverser.nodes();
System.out.println("All Nodes:");      // First Task
for(Node n:nodes){
System.out.println(n.getId());
}
Iterable<Relationship> rels = traverser.relationships();
System.out.println("All Relations:");  // Second Task
for(Relationship r:rels){
System.out.println(r.getId());
}
Iterator<Path> paths = traverser.iterator();  // Third Task
while(paths.hasNext()){
    System.out.println(paths.next());
}

I need to do 3 tasks as commented in the code:

  1. Print all the node IDs related to node no. 21
  2. Print all the relation IDs related to node no. 21
  3. Traverse all the paths related to node no. 21

Tasks 1 & 2 are working fine. But when I try to do traverser.iterator() in 3rd task it throws an Exception saying:

java.lang.IllegalAccessError: tried to access class org.neo4j.helpers.collection.WrappingResourceIterator from class org.neo4j.rest.graphdb.traversal.RestTraverser

Can anyone please check why this is happening or if I am doing wrong then what is the right method to do it. Thanks in Advance.

Was it helpful?

Solution

I don't believe using the Neo4j Traversal Framework via the REST DB binding is properly supported, nor is it advisable. If you traverse via REST, each node and each relationship will be retrieved over the network as the traversal proceeds, incurring a tremendous overhead for the traversal.

Edit: The above is not true, the REST traverser is smarter than I thought.

In general, it will be faster to use Cypher, and access the Neo4j Server using JDBC. Read more about JDBC here: https://github.com/neo4j-contrib/neo4j-jdbc

If you really want to use the Traversal Framework, you should use Server Extensions, which allow you to design a traversal to run on the server itself, and then only move the result of the traversal over the network. Read more about server extensions here: http://docs.neo4j.org/chunked/stable/server-unmanaged-extensions.html

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