Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring数据Neo4j实体路径映射_Java_Neo4j_Spring Data Neo4j - Fatal编程技术网

Java Spring数据Neo4j实体路径映射

Java Spring数据Neo4j实体路径映射,java,neo4j,spring-data-neo4j,Java,Neo4j,Spring Data Neo4j,我有一个独立的Neo4j数据库2.1.6。我从一个基于web的Spring boot项目开始,并在Neo4j 3.2.1版本中添加了Spring数据。我正在尝试映射路径中的节点。我希望能够拉一棵深度不确定的树,并将其映射到java实体中 此查询: match p=(a:fakea)-[*]->(:fakeb) where a.aId = 1 return p; 返回两条路径: {"start":"http://localhost:8180/db/data/node/593222","no

我有一个独立的Neo4j数据库2.1.6。我从一个基于web的Spring boot项目开始,并在Neo4j 3.2.1版本中添加了Spring数据。我正在尝试映射路径中的节点。我希望能够拉一棵深度不确定的树,并将其映射到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"}
我已经尝试使用我在这里找到的信息以几种不同的方式映射它:

我的当前存储库:

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);
例如,当我尝试检查EntityPath结构长度的任何其他部分时,我会收到类似的空指针

如何查询不同深度的树路径结构并将结果映射到正确的节点实体?我特别想要路径中包含的节点。

试试这个

而不是你现在拥有的:

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);
使用:

该查询将获取FakeA的一个实例,并找到与之关联的FakeA,在本例中假设只有一个匹配项。如果可以有多个,请更改meth方法签名以返回一个集合


然而,我认为您也工作得太辛苦了,没有利用SpringData内置的动态查找器。我建议您仔细阅读本教程:

您是要获取路径信息还是要在路径中标识特定节点?我正在尝试检索路径中的特定节点。为了清晰起见,我将编辑我的原始问题。转到此链接以获取解决方案:我最终使用的解决方案是返回单个对象,并使用Relatedto和Fetch注释映射所需的关系。我后来发现,这是实现这一目标的较慢方法之一。
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)
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<FakeA> {

@Query("start p=node{0} match (p)-[*]->(a:fakea) return a;")
public FakeA getTree(FakeA fakeA);