我有一个独立的Neo4j数据库2.1.6。我从一个基于Web的Spring启动项目开始,并添加了Spring Data Neo4j 3.2.1版本。我试图映射路径内的节点。我希望能够拉出一个不确定深度的树并将其映射到Java实体中。Spring数据Neo4j实体路径映射
此查询:
match p=(a:fakea)-[*]->(:fakeb) where a.aId = 1
return p;
回报两条路径:
{"start":"http://localhost:8180/db/data/node/593222","nodes":["http://localhost:8180/db/data/node/593222","http://localhost:8180/db/data/node/593223","http://localhost:8180/db/data/node/593224","http://localhost:8180/db/data/node/593225"],"length":3,"relationships":["http://localhost:8180/db/data/relationship/2489542","http://localhost:8180/db/data/relationship/2489543","http://localhost:8180/db/data/relationship/2489544"],"end":"http://localhost:8180/db/data/node/593225"}
{"start":"http://localhost:8180/db/data/node/593222","nodes":["http://localhost:8180/db/data/node/593222","http://localhost:8180/db/data/node/593223","http://localhost:8180/db/data/node/593226","http://localhost:8180/db/data/node/593227"],"length":3,"relationships":["http://localhost:8180/db/data/relationship/2489542","http://localhost:8180/db/data/relationship/2489545","http://localhost:8180/db/data/relationship/2489546"],"end":"http://localhost:8180/db/data/node/593227"}
我试图映射它使用几个不同信息的方法,我在这里找到:
Spring data wth ne04j error...error while retrieving paths
@Query shortestPath return type in Spring Data Neo4j
我目前的资料库:
public interface FakeRepository extends GraphRepository<FakeA> {
@Query("match p=(a:fakea)-[*]->(:fakeb) where a.aId = {0} return p;")
public EntityPath<FakeA, FakeB> getTree(Long aId);
我还试图建立一个共同的抽象类:
public interface FakeRepository extends GraphRepository<FakeAbs> {
@Query("match p=(a:fakea)-[*]->(:fakeb) where a.aId = {0} return p;")
public EntityPath<FakeAbs, FakeAbs> getTree(Long aId);
我无法检索到任何有用的数据。我也无法找到我列出的帖子中提到的EndResult类。我也尝试用结果包装EntityPath(在回购中)。
Result<EntityPath<FakeAbs, FakeAbs>> path = fr.getTree(1l);
EntityPath<FakeAbs, FakeAbs> first = path.iterator().next();
first.endNode();
提出:
Null pointer:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
at org.springframework.data.neo4j.support.path.ConvertingEntityPath.endNode(ConvertingEntityPath.java:112)
我收到类似空指针当我尝试检查EntityPath结构(长度()例如)的任何其它部分。
如何查询不同深度的树路径结构并将结果映射到正确的节点实体?我特别想要包含在路径中的节点。
你想获得路径信息还是想要在路径中标识特定节点? –
我正在尝试检索路径中的特定节点。为了清晰起见,我将编辑我的原始问题。 – jake
转到此链接的解决方案: https://stackoverflow.com/questions/32962032/how-do-i-query-for-paths-in-spring-data-neo4j-4?rq=1 – joe