0

I'm trying to parametrize the match part of a annotated Cypher query with Spring-Data-Neo4j-3.1.4 as follows. The first method is working. Passing the node type as parameter in the second method fails.

public interface NodeRepository extends CrudRepository<Node, Long> {

    @Query("START n=node(*) MATCH (n:Organization) RETURN n")
    List<Node> findByNodeType();

    @Query("START n=node(*) MATCH (n:{0}) RETURN n")
    List<Node> findByNodeType(String nodeType);
}

Exception is:

org.springframework.dao.InvalidDataAccessResourceUsageException: 
  Error executing statement START n=node(*) MATCH (n:{0}) RETURN n;     
  nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: 
  Error executing statement START n=node(*) MATCH (n:{0}) RETURN n; 
  nested exception is Invalid input '{': 
  expected whitespace or a label name (line 1, column 26)
  "START n=node(*) MATCH (n:{0}) RETURN n"
  at org.springframework.data.neo4j.support.query.CypherQueryEngineImpl.query(CypherQueryEngineImpl.java:61)
  at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:107) 
  at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery$1.doWithGraph(GraphRepositoryQuery.java:89) 
  at org.springframework.data.neo4j.support.Neo4jTemplate.doExecute(Neo4jTemplate.java:457) 
  at org.springframework.data.neo4j.support.Neo4jTemplate.access$000(Neo4jTemplate.java:87) 
  at org.springframework.data.neo4j.support.Neo4jTemplate$2.doInTransaction(Neo4jTemplate.java:471)

How do pass the node as a parameter to the Cypher query?

3
  • Also change your queries to: MATCH (n:Organization) RETURN n May 27, 2015 at 20:08
  • 1
    You can try: MATCH (n) WHERE {0} IN labels(n) RETURN n but it won't be efficient, why would you want to do that in the first place ?? May 27, 2015 at 20:10
  • MATCH (n) WHERE {0} IN labels(n) RETURN n is working. You should post this as an answer. May 28, 2015 at 8:20

2 Answers 2

1

Change your queries to: MATCH (n:Organization) RETURN n

You can try: MATCH (n) WHERE {0} IN labels(n) RETURN n

but it won't be efficient, why would you want to do that in the first place ?

Labels are not allowed as parameters (yet) for query-planner reasons.

0

If you read the exception : Invalid input '{':

It means that the query is wrong. In fact you cannot pass labels as parameter in a Cypher query, so simple it is ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.