neo4j报错:Relationship ()-[]->() cannot be fully hydrated because one or more required node entities have not been part of the result set.

1、报错信息

在使用spring data neo4j 查询neo4j中的数据时,我用了自定义的查询语句,即

@Query(value = "match (n:NodeType) - [r:RELATION_TYPE] -> (m:NodeType) where n.id=$0 return r")
List<RelationType> findRelation(Integer id);

执行程序后,报错如下:

Relationship (30)-[RELATION_TYPE]->(29) cannot be fully hydrated because one or more required node entities have not been part of the result set.

报错信息看得我很迷,不知所云。。。

2、原因&解决方案

经过一波面向谷歌编程后,=_=!我悟了!

原来是我自定义的neo4j查询语句出现了问题,“return”字段后应该返回两端节点和边,如下:

@Query(value = "match (n:NodeType) - [r:RELATION_TYPE] -> (m:NodeType) where n.id=$0 return n, r, m")
// 或者 @Query(value = "match p=(n:NodeType) - [r:RELATION_TYPE] -> (m:NodeType) where n.id=$0 return p")
List
<RelationType> findRelation(Integer id);

这样看来,前面的报错信息可能的意思是:

如果我要查询neo4j中的边,需要在neo4j语句中不只返回边,还要返回两端节点。这样我们查询方法 findRelation(...) 返回的结果集就是 neo4j语句返回结果的一部分了。

posted @ 2021-04-19 16:36  <予安>  阅读(834)  评论(2编辑  收藏  举报