0

I am currently using spring-data-neo4j to get paths between two nodes. Here's the repository:

@Query("MATCH p=((n:GLNode)-[:GLRelationship*0..]->(m:GLNode)) WHERE id(n)={0} and id(m)={1} RETURN nodes(p)")
Collection<GLNode> getAllPathes(Long sid, Long eid);

However, exception says that only 1 row is expceted but 2 found.

For more information, if I change the code into:

@Query("MATCH p=((n:GLNode)-[:GLRelationship*0..]->(m:GLNode)) WHERE id(n)={0} and id(m)={1} RETURN nodes(p)")
Collection<Collection<GLNode>> getAllPathes(Long sid, Long eid);

I can get some response which is NOT correctly mapped into domain GLNode, e.g., id of node is missing.

if I only find the shortest path, e.g.,

@Query("MATCH p=shortestPath((n:GLNode)-[:GLRelationship*0..]->(m:GLNode)) WHERE id(n)={0} and id(m)={1} RETURN nodes(p)")
Collection<GLNode> getAllPathes(Long sid, Long eid);

Then everything works fine.

So, what is the correct way to map multiple paths queried from neo4j into a single object in java?

Thanks.

=============== UPDATE ==============

I have come up with a temporary solution by only fetching id of the nodes, i.e.,

@Query("MATCH p=((n:GLNode)-[:GLRelationship*0..]->(m:GLNode)) WHERE id(n)={0} AND id(m)={1} RETURN [node in nodes(p) | id(node)] AS nodes, [rel in relationships(p) | id(rel)] AS  rels")
Collection<HashMap> getAllPathes(Long sid, Long eid);

It works only when the client knows all the graph.

===================== UPDATE 2 =======================

The only 1 row is expected but 2 found exception is actually thrown with the following code:

@Query("MATCH p=((n:GLNode)-[:GLRelationship*0..]->(m:GLNode)) WHERE id(n)={0} AND id(m)={1} RETURN nodes(p)")
HashMap getAllPathes(Long sid, Long eid);

Here's the exception detail:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.RuntimeException: Result not of expected size. Expected 1 row but found 15
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    com.hersbitcloud.cancercloud.CORSFilter.doFilter(CORSFilter.java:24)
    org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause

java.lang.RuntimeException: Result not of expected size. Expected 1 row but found 15
    org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.queryForObject(ExecuteQueriesDelegate.java:65)
    org.neo4j.ogm.session.Neo4jSession.queryForObject(Neo4jSession.java:308)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
    org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    com.sun.proxy.$Proxy51.queryForObject(Unknown Source)
    org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:78)
    org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:52)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)
    org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
    com.sun.proxy.$Proxy62.getAllPathes(Unknown Source)
    com.hersbitcloud.cancercloud.services.GLService.getAllPathes(GLService.java:77)
    com.hersbitcloud.cancercloud.controllers.GLController.getAllPathes(GLController.java:64)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    com.hersbitcloud.cancercloud.CORSFilter.doFilter(CORSFilter.java:24)
    org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Steven Luo
  • 2,350
  • 3
  • 18
  • 35
  • Are you using SDN 4.1 or SDN 4? – Luanne Apr 07 '16 at 11:05
  • @Luanne I am using SDN 4 – Steven Luo Apr 07 '16 at 11:26
  • @Luanne I upgraded to SDN 4.1, but the problem still exists. – Steven Luo Apr 08 '16 at 00:31
  • I'm unable to reproduce the exception from your first query on SDN 4.1 (1 row expected but found 2). Can you supply a dataset/code/test? – Luanne Apr 08 '16 at 03:29
  • @Luanne I am totally lost among the trials. I cannot reproduce this exception either. But the question still exists, using `Collection`, the returned collection is not in the right order, i.e., multiple paths are overlapping with each other. – Steven Luo Apr 08 '16 at 07:01
  • @Luanne I finally reproduced the exception. Please refer to UPDATE 2. – Steven Luo Apr 08 '16 at 07:22
  • So, 15 nodes are being returned, but you want them to map to a single HashMap? The OGM won't be able to do that for you. Why not get back a collection of GLNode? – Luanne Apr 08 '16 at 09:54
  • @Luanne I understand that. But the problem is that if using `Collection` or `Collection`, the returned array is the overlapped paths, and can not be resolved into multiple paths. – Steven Luo Apr 08 '16 at 11:37
  • Ah okay. There's no real concept of a path entity in SDN 4. At best, the components of the path will hydrate domain entities. – Luanne Apr 11 '16 at 08:23

0 Answers0