springspring-data-neo4j

How can we create an node with manual query in spring data neo4j?


Create an node manually via repo interface but neo4j driver internally raise an exception as


Caused by: org.neo4j.driver.exceptions.ClientException: Invalid input '{': expected a parameter (line 1, column 22 (offset: 21))
"CREATE(a:Association {a.name:{0}}) RETURN true"
                       ^

Below is the code snippet:


    `@Repository
    public interface AssociationRepo extends Neo4jRepository {
 
     @Query("CREATE(a:Association {a.name:{0}}) RETURN a") -- what is wrong in this line ?
     Association addAssociation(String name);

    }`

Caller code :


   ` @Override
    public boolean addAssociationToCountry(String countryCode, Association association) {    
    
     repo.addAssociation(association.getName());    
     return true;

   }`

I checked whole of internet but didn't find any solution.`


Solution

  • You are very close to the right syntax. The problem is the node name, you are using within the curly brackets.

    Instead of (a:Association {a.name:{0}}) it should be (a:Association {name:{0}}) because the node boundaries already define that the properties belong to this very node.