1

I am trying to retrieve the shortest path between two nodes in a simple graph. I am getting a

NullPointerException at org.springframework.data.neo4j.support.path.ConvertingEntityPath.nodes(ConvertingEntityPath.java:137)

Where i figured that delegate is null, but i don't know why.

Here is my repository with the cypher query (tested and working on neo4j UI) :

@Query("START from=node({0}), to=node({1}) MATCH path=(from)<-[:NETWORK_LINK*]->(to) RETURN path")
Iterable<EntityPath<DGNode, DGNode>> getShortestNetworkPathBetween(Long fromid, Long toid);

and my test code :

System.out.println("Network path from "+srv1.getId()+" to "+srv5.getId()+" :  \n");

Iterable result = nodeRepository.getShortestNetworkPathBetween(srv1.getId(), srv5.getId());

Iterable<EntityPath<DGNode,DGNode>> paths = (Iterable<EntityPath<DGNode,DGNode>>) result;
for(EntityPath<DGNode,DGNode> path : paths) {
    String nodes = "";
    while (path.nodeEntities().iterator().hasNext()) {
        nodes += ", " + ((DGNode) path.nodeEntities().iterator().next()).getName();
    }
    System.out.println("From " + path.startNode().getClass().getName() + " to " + path.endNode().getClass().getName() + " : " + nodes);
}

My code is based on the following example spring-data-neo4j-examples. I also checked this post but with no help: the request return a collection (QueryResultBuilder cannot be cast to EntityPath) and, by the way EndResult seems to have been renamed to Result in this version.

Community
  • 1
  • 1
Xilhion
  • 11
  • 2
  • So, using step by step debug i found out that the query did return a result where each path found is a HashMap and, according to the debug, this cannot be converted to a Path, which is why ConvertingEntityPath.delegate is null. Still, i don't figure out what i'm doing wrong, should i use another return type in my repository ? If so, which one ? Thanks. – Xilhion Aug 13 '14 at 15:09
  • One step further! Thanks to this discution [link](https://groups.google.com/forum/#!topic/neo4j/Aq2jsdY41cM), this is due to the fact that i am connecting to an external Neo4j database using SpringRestGraphDatabase. When using an embedded one, the issue is gone and i have my paths... Anyone knows how to fix this ? – Xilhion Aug 13 '14 at 15:33
  • use Iterable as return type – gaurhari dass May 24 '18 at 15:07

0 Answers0