title: Create Neo4j relation in spring data with existing node
body: <p>I am trying to create relationships between nodes in Neo4j. I am using the <strong>Neo4J(2.1.8 Community)</strong> &amp; <strong>spring-data-neo4j(3.3.0.RELEASE)</strong>.</p>
  <p>I am trying to create the below relation.</p>
  <p>Create a new Employee(node) which will be reporting(Empty Relation) to the Manager(node) which is there in DB (Searching by name). I have used the below query.</p>
  <pre><code>public interface EmployeeRepository extends GraphRepository&lt;Employee&gt; {
  
  @Query(&quot;START employee=node:({0}), manager=node:Employee(name={1}) CREATE employee-[:REPORTS_TO]-&gt;manager&quot;)
  void addNewEmployee(Employee employee, String managerName);}
  </code></pre>
  <p>I got the below error.</p>
  <pre><code>Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START employee=node:({0}), manager=node:Employee(name={1}) CREATE employee-[:REPORTS_TO]-&gt;manager; nested exception is Invalid input '(': expected whitespace or an identifier (line 1, column 21)
  &quot;START employee=node:({0}), manager=node:Employee(name={1}) CREATE employee-[:REPORTS_TO]-&gt;manager&quot;
                       ^
  </code></pre>
  <p>Can anyone please tell me what is wrong with this query? Also if this is not the right way to create the relations using <strong>GraphRepository</strong> then what else I can use to accomplish the same.</p>
  <p>Thanks in advance.</p>
  <p><strong>Note:</strong> I have used <a href="http://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#query_and_finder_methods" rel="nofollow noreferrer">this</a> to learn the queries in Spring Data for Neo4j. Where they have shown the basic queries.</p>
  <p><strong>Updated:</strong> Employee Class</p>
  <pre><code>@NodeEntity
  public class Employee {
  
  @GraphId
  private Long id;
  private String name;
  private String department;
  
  @RelatedTo(type = &quot;REPORTS_TO&quot;)
  private Employee reportsTo;
  
  @RelatedTo(type = &quot;REPORTS_TO&quot;, direction = Direction.INCOMING)
  Set&lt;Employee&gt; directReport;
  
  public Employee() {
  }
  
  public Employee(String name, String department) {
      this.name = name;
      this.department = department;
  }
  
  public Long getId() {
      return id;
  }
  
  public String getName() {
      return name;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public String getDepartment() {
      return department;
  }
  
  public void setDepartment(String department) {
      this.department = department;
  }
  
  public Employee getReportsTo() {
      return reportsTo;
  }
  
  public void setReportsTo(Employee reportsTo) {
      this.reportsTo = reportsTo;
  }
  
  public Set&lt;Employee&gt; getDirectReport() {
      return directReport;
  }
  
  public void setDirectReport(Set&lt;Employee&gt; directReport) {
      this.directReport = directReport;
  }
  
  @Override
  public int hashCode() {
      return super.hashCode();
  }
  
  @Override
  public boolean equals(Object obj) {
      return super.equals(obj);
  }
  
  @Override
  public String toString() {
      return &quot;Employee{&quot; + &quot;id=&quot; + id + &quot;, name=&quot; + name + &quot;, department=&quot; + department + '}';
  }
  }
  </code></pre>