1
votes

Using Cypher, multiple nodes are selected by listing them separated by commas:

START n=node(1, 2, 3) RETURN n

http://docs.neo4j.org/chunked/milestone/query-start.html#start-multiple-nodes-by-id

I would like to use this with Spring Data @Query but it does not work:

@Query("start person=node({0}) match (person)-[:has_friends]->(friend) return friend")
private Iterable<Person> friends(Iterable<Person> persons);

Edit: Here is the stacktrace:

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)

Any idea?

3
Can you pass in a collection / list instead of an iterable? - Michael Hunger
No I have the same error. I've added the stacktrace. - Cedric Thiebault
Should work if you pass in a collection of the nodeIds - s_t_e_v_e

3 Answers

0
votes

You should start from node(*) instead of node(0).

0
votes

I assume that Person is annotated with @NodeEntitiy. As the stacktrace states, Node(s) (NodeId(s) (Long), work as well) are expected, if you want to substitute it for the {0} in start person=node({0}) ...

0
votes

In the current version of SDN this query should work:

@Query("(person)-[:has_friends]->(friend) where id(person) IN {0} return friend")
private Iterable<Person> friends(Iterable<Person> persons);