使用Cypher,通过以逗号分隔它们来选择多个节点:
START n=node(1, 2, 3) RETURN n
http://docs.neo4j.org/chunked/milestone/query-start.html#start-multiple-nodes-by-id
我想在Spring Data @Query中使用它,但它不起作用:
@Query("start person=node({0}) match (person)-[:has_friends]->(friend) return friend")
private Iterable<Person> friends(Iterable<Person> persons);
修改 这是堆栈跟踪:
java.lang.ClassCastException: Person cannot be cast to org.neo4j.graphdb.Node
at org.neo4j.kernel.impl.traversal.AsOneStartBranch.toBranches(AsOneStartBranch.java:65)
at org.neo4j.kernel.impl.traversal.AsOneStartBranch.<init>(AsOneStartBranch.java:59)
at org.neo4j.kernel.impl.traversal.BidirectionalTraverserIterator.<init>(BidirectionalTraverserIterator.java:81)
at org.neo4j.kernel.impl.traversal.BidirectionalTraverserImpl.instantiateIterator(BidirectionalTraverserImpl.java:44)
at org.neo4j.kernel.impl.traversal.AbstractTraverser.iterator(AbstractTraverser.java:83)
at org.neo4j.cypher.internal.pipes.matching.BidirectionalTraversalMatcher.findMatchingPaths(BidirectionalTraversalMatcher.scala:73)
at org.neo4j.cypher.internal.pipes.TraversalMatchPipe$$anonfun$createResults$1.apply(TraversalMatchPipe.scala:32)
at org.neo4j.cypher.internal.pipes.TraversalMatchPipe$$anonfun$createResults$1.apply(TraversalMatchPipe.scala:29)
at scala.collection.Iterator$$anon$21.hasNext(Iterator.scala:371)
at scala.collection.Iterator$$anon$21.hasNext(Iterator.scala:371)
at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334)
at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334)
at org.neo4j.cypher.PipeExecutionResult.hasNext(PipeExecutionResult.scala:138)
at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334)
at scala.collection.JavaConversions$IteratorWrapper.hasNext(JavaConversions.scala:562)
at org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)
有什么想法吗?
答案 0 :(得分:0)
您应该从node(*)
而不是node(0)
开始。
答案 1 :(得分:0)
我认为Person
注明了@NodeEntitiy
。正如堆栈跟踪所述,Node
(s)( NodeId(s)(Long
),也可以工作,如果你想用它代替{{ 1}}在{0}
答案 2 :(得分:0)
在当前版本的SDN中,此查询应该有效:
@Query("(person)-[:has_friends]->(friend) where id(person) IN {0} return friend")
private Iterable<Person> friends(Iterable<Person> persons);