检索路径时出现ne04j错误的弹簧数据错误...

时间:2013-03-13 03:56:16

标签: neo4j spring-data-neo4j

我正在使用neo4j的弹簧数据。

我使用@Query注释将查询放入存储库,查询如下

@Query(value = "START me=node({0}), friend=node({1}) "
            + "MATCH p=shortestPath(me-[:ACTIVEFRIEND*..]->friend)"
            + " RETURN p")

public Iterable<EntityPath<User, User>> getShortestPathBetween(User a, User b);

在控制器中我以

的身份访问它
 Iterable<EntityPath<User, User>> shortestPathBetween = this.queryService.getShortestPathBetween(user, friend);
        for (EntityPath<User, User> path : shortestPathBetween) {
            Iterator<User> iter = path.<User>nodeEntities().iterator();
        }

当它尝试访问path.nodeEntities时,会导致此错误:

  带有根本原因的

嵌套异常是java.lang.NullPointerException]   显示java.lang.NullPointerException
  在org.springframework.data.neo4j.support.path.ConvertingEntityPath.nodes(ConvertingEntityPath.java:137)
  在org.springframework.data.neo4j.support.path.ConvertingEntityPath.nodeEntities(ConvertingEntityPath.java:69)
  在com.laindain.cms.controller.QueryController.getShortestPathBetween(QueryController.java:194)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)           在java.lang.reflect.Method.invoke(Method.java:601)           在org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)           在org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)           在org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)           在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)           在org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)           在org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)           在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)           在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)           在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)           在org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:647)           在javax.servlet.http.HttpServlet.service(HttpServlet.java:728)           在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)           在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)           在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)           在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)           在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)           在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)           在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)           在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)           在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)           在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)           at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:589)           在org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:1822)           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)           at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)           在java.lang.Thread.run(Thread.java:722)

如果有人能帮助我,我将不胜感激。

由于 与Hemant

1 个答案:

答案 0 :(得分:3)

尝试以这种方式定义方法:

public EndResult<EntityPath<User, User>> getShortestPathBetween(User a, User b);

因为查询返回路径而不是路径集合。 您可以按如下方式获得结果:

EntityPath<User, User> shortestPathBetween =
this.queryService.getShortestPathBetween(user, friend).to(EntityPath);

然后可以使用返回的 EntityPath 上的 nodeEntities() relationshipEntities()方法访问路径上的节点和关系