Spring 数据 Neo4j 关系无法正常工作
Spring Data Neo4j Relationships not working correctly
我是关系数据背景下的 neo4j 新手。我在创建 spring 服务以与我的 neo4j 数据库交互时遇到问题。
在我的数据库中,我有一个名为 Row
的节点 'type' / 标签,它与另一个 Row
节点
具有分层父子关系
我这样定义我的关系:
MATCH
(parent:Row),
(child:Row)
WHERE
child.parentUuid = parent.uuid
CREATE (parent)-[:ParentChild]->(child)
在Spring中,我的行实体的关系定义为:
@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。
(这是从 复制的,但这个问题不是重复的。)
我是关系数据背景下的 neo4j 新手。我在创建 spring 服务以与我的 neo4j 数据库交互时遇到问题。
在我的数据库中,我有一个名为 Row
的节点 'type' / 标签,它与另一个 Row
节点
我这样定义我的关系:
MATCH
(parent:Row),
(child:Row)
WHERE
child.parentUuid = parent.uuid
CREATE (parent)-[:ParentChild]->(child)
在Spring中,我的行实体的关系定义为:
@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。
(这是从