springspring-bootneo4jspring-data-neo4j-4

how to pass relationship query parameter in spring data neo4j


returns error with below annoation.

@Query(value ="MATCH (n:Phone {phoneId:{0}})-[f:calling*0..{1}]-(m) OPTIONAL MATCH (m)-[r]-() return m,r")  
List<QueryPOJO> graph(String name,int level);

Description: Parameter maps cannot be used in MATCH patterns (use a literal map instead, eg. "{id: {param}.id}") (line 1, column 45 (offset: 44))

we need a elegant method to resolve this problem instead of write many interfaces.

   @Query(value ="MATCH (n:Phone {phoneId:{0}})-[f:calling*0..2]-(m) 
   OPTIONAL MATCH (m)-[r]-() return m,r")  
   List<QueryPOJO> grapht_2(String name,int level);

   @Query(value ="MATCH (n:Phone {phoneId:{0}})-[f:calling*0..3]-(m) 
   OPTIONAL MATCH (m)-[r]-() return m,r")  
   List<QueryPOJO> grapht_3(String name,int level);

cypher cannot resolve level relationship problem.

   MATCH (n:Person {name:'AAA'})-[f]-(m) where type(f)="Follow" OPTIONAL MATCH (m)-[r]-() return m,r

Solution

  • You may need to resort to "manually" constructing the Cypher statement as a String and executing it through the Session, which allows execution of arbitrary Cypher queries via its query, queryForObject and queryForObjects methods.