Reputation: 3481
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?
Upvotes: 0
Views: 988
Reputation: 41676
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.
Upvotes: 1
Reputation: 20175
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 ;-)
Upvotes: 0