Issue
I am fairly new to neo4j coming from a relational data background. I'm having issues creating a spring service to interact with my neo4j database.
In my database I have a node 'type' / label called Row
which has a hierarchical parent child relationship to another Row
node
I defined my relationship like the following:
MATCH
(parent:Row),
(child:Row)
WHERE
child.parentUuid = parent.uuid
CREATE (parent)-[:ParentChild]->(child)
In Spring, my Row Entity's relationship is defined as:
@Node
data class Row(
//fields
@Relationship(type = "ParentChild", direction = Direction.OUTGOING)
var children: List<Row> = emptyList(),
) {}
My relationships appear to be working correctly when I run a cypher query directly on my database, but when I run Spring's built in findByFieldTitle
it throws an error and says the relationships don't match up.
Does anybody know what I'm doing wrong?
Edit: Here is the stack trace:
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))
Solution
There is nothing wrong with your mapping / model The problem is in the version of Neo4j you are using. It has a query planner bug. I do not know when it appeared but it is solved with 4.3.3 / 4.2.10 and higher.
This combined with some needed query improvements in SDN 6.1.6 lead to the problematic constellation right now. I would suggest to manually set the Spring Data Neo4j version down to 6.1.5 if you cannot upgrade the database.
(This is copied from Spring Data neo4j access relationship from both sides but this question is not a duplicate.)
Answered By - meistermeier
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.