1

使用 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)

任何想法?

4

3 回答 3

0

你应该从而node(*)不是开始node(0)

于 2013-09-09T07:36:31.223 回答
0

我假设这Person是用@NodeEntitiy. 正如堆栈跟踪所述,如果您想用Node(s) ( NodeId(s) ( Long) 来代替{0}instart person=node({0}) ...

于 2013-09-10T10:07:39.847 回答
0

在当前版本的 SDN 中,此查询应该可以工作:

@Query("(person)-[:has_friends]->(friend) where id(person) IN {0} return friend")
private Iterable<Person> friends(Iterable<Person> persons);
于 2014-12-02T11:19:55.557 回答