spring - Spring Data Neo4j 关系无法正常工作
问题描述
我对来自关系数据背景的 neo4j 相当陌生。我在创建 spring 服务以与我的 neo4j 数据库交互时遇到问题。
在我的数据库中,我有一个名为“类型”/标签的节点,它与另一个节点Row
具有分层父子关系Row
我将我的关系定义如下:
MATCH
(parent:Row),
(child:Row)
WHERE
child.parentUuid = parent.uuid
CREATE (parent)-[:ParentChild]->(child)
在 Spring 中,我的 Row Entity 的关系定义为:
@Node
data class Row(
//fields
@Relationship(type = "ParentChild", direction = Direction.OUTGOING)
var children: List<Row> = emptyList(),
) {}
当我直接在我的数据库上运行密码查询时,我的关系似乎工作正常,但是当我运行 Spring 内置时,findByFieldTitle
它会引发错误并说关系不匹配。
有人知道我做错了什么吗?
编辑:这是堆栈跟踪:
org.neo4j.driver.exceptions.DatabaseException: Expected
RegularSinglePlannerQuery(QueryGraph {Nodes: [' rootNodeIds@7'], Predicates: ['id(` rootNodeIds@7`) IN $rootNodeIds']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map(),Map( n@87 -> FunctionInvocation(Namespace(List()),FunctionName(collect),false,Vector(Variable( rootNodeIds@7)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87'], Optional Matches: : ['QueryGraph {Rels: ['( NODE105)--[relationshipIds]--( NODE126)'], Predicates: ['id(relationshipIds) IN $relationshipIds']}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87)),Map(__sr__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relationshipIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__'], Optional Matches: : ['QueryGraph {Nodes: ['relatedNodeIds'], Predicates: ['id(relatedNodeIds) IN $relatedNodeIds']}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87), __sr__ -> Variable(__sr__)),Map(__srn__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relatedNodeIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),UnwindProjection( rootNodeIds@384,Variable( n@87)),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', ' rootNodeIds@384', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map( n@416 -> Variable( rootNodeIds@384), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@416', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map(__sn__ -> Variable( n@416), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),None,None)),None)),None)),None)),None)),None)
Instead, got:
RegularSinglePlannerQuery(QueryGraph {Nodes: [' rootNodeIds@7'], Predicates: ['id(` rootNodeIds@7`) IN $rootNodeIds']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map(),Map( n@87 -> FunctionInvocation(Namespace(List()),FunctionName(collect),false,Vector(Variable( rootNodeIds@7)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87'], Optional Matches: : ['QueryGraph {}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87)),Map(__sr__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relationshipIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__'], Optional Matches: : ['QueryGraph {Nodes: ['relatedNodeIds'], Predicates: ['id(relatedNodeIds) IN $relatedNodeIds']}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87), __sr__ -> Variable(__sr__)),Map(__srn__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relatedNodeIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),UnwindProjection( rootNodeIds@384,Variable( n@87)),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', ' rootNodeIds@384', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map( n@416 -> Variable( rootNodeIds@384), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@416', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map(__sn__ -> Variable( n@416), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),None,None)),None)),None)),None)),None)),None)
Differences:
- Tail
A: Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87'], Optional Matches: : ['QueryGraph {Rels: ['( NODE105)--[relationshipIds]--( NODE126)'], Predicates: ['id(relationshipIds) IN $relationshipIds']}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87)),Map(__sr__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relationshipIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__'], Optional Matches: : ['QueryGraph {Nodes: ['relatedNodeIds'], Predicates: ['id(relatedNodeIds) IN $relatedNodeIds']}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87), __sr__ -> Variable(__sr__)),Map(__srn__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relatedNodeIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),UnwindProjection( rootNodeIds@384,Variable( n@87)),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', ' rootNodeIds@384', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map( n@416 -> Variable( rootNodeIds@384), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@416', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map(__sn__ -> Variable( n@416), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),None,None)),None)),None)),None)),None))
B: Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87'], Optional Matches: : ['QueryGraph {}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87)),Map(__sr__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relationshipIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__'], Optional Matches: : ['QueryGraph {Nodes: ['relatedNodeIds'], Predicates: ['id(relatedNodeIds) IN $relatedNodeIds']}']},InterestingOrder(RequiredOrderCandidate(List()),List()),AggregatingQueryProjection(Map( n@87 -> Variable( n@87), __sr__ -> Variable(__sr__)),Map(__srn__ -> FunctionInvocation(Namespace(List()),FunctionName(collect),true,Vector(Variable(relatedNodeIds)))),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),UnwindProjection( rootNodeIds@384,Variable( n@87)),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@87', ' rootNodeIds@384', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map( n@416 -> Variable( rootNodeIds@384), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),Some(RegularSinglePlannerQuery(QueryGraph {Arguments: [' n@416', '__sr__', '__srn__']},InterestingOrder(RequiredOrderCandidate(List()),List()),RegularQueryProjection(Map(__sn__ -> Variable( n@416), __sr__ -> Variable(__sr__), __srn__ -> Variable(__srn__)),QueryPagination(None,None),Selections(Set())),None,None)),None)),None)),None)),None))
解决方案
您的映射/模型没有问题 问题出在您使用的 Neo4j 版本中。它有一个查询计划程序错误。我不知道它何时出现,但它已通过 4.3.3 / 4.2.10 及更高版本解决。
这与 SDN 6.1.6 中一些必要的查询改进相结合,导致了现在有问题的星座。如果您无法升级数据库,我建议手动将 Spring Data Neo4j 版本设置为 6.1.5。
(这是从双方的Spring Data neo4j访问关系中复制的,但这个问题不是重复的。)
推荐阅读
- git - 检测 CodeCommit 中的更改并在 EC2 实例中运行命令
- scala - 如何在一个对象中隐含在另一个对象之前?
- algorithm - 切棒的贪心算法
- systemd - systemctl status(不是底层服务)中的错误 systemctl status 返回什么返回码?
- kubernetes - 来自服务器的错误 (NotFound): deployments.extensions "1" not found(在 Kubernetes 中删除部署时出错)
- java - 从Java中的串行端口拆分字符串
- c# - C# null 条件运算符在调用异步任务时有什么不同吗?
- python-3.x - 如何在 Visual Studio 2017 上安装 pygame?
- r - 如何在单独的页面上为数据集中的每一列创建直方图
- python - 如何抓取嵌套的 div 和 ol 类