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.