【发布时间】:2015-01-14 21:26:53
【问题描述】:
我有一个独立的 Neo4j 数据库 2.1.6。我从一个基于 Web 的 Spring Boot 项目开始,并添加了 Spring Data Neo4j 3.2.1 Release。我正在尝试映射路径内的节点。我希望能够拉出不确定深度的树并将其映射到 java 实体中。
这个查询:
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 类。我还尝试用 Result 包装 EntityPath(也在 repo 中)。
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 结构的任何其他部分(例如 length())时,我会收到类似的空指针。
如何查询不同深度的树路径结构并将结果映射到正确的节点实体?我特别想要路径中包含的节点。
【问题讨论】:
-
您是在尝试获取路径信息还是希望在路径中识别特定节点?
-
我正在尝试检索路径中的特定节点。为了清楚起见,我将编辑我原来的问题。
-
前往此链接获取解决方案:stackoverflow.com/questions/32962032/…
标签: java neo4j spring-data-neo4j