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?
MATCH (n:Organization) RETURN n
– Michael HungerMATCH (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 ?? – Michael HungerMATCH (n) WHERE {0} IN labels(n) RETURN n
is working. You should post this as an answer. – uı6ʎɹnɯ ꞁəıuɐp