title: How to implement a bidirectional relationship in Spring Data Neo4j?
body: <p>I am modelling a very simple use case, using Spring Data Neo4j: I want to have Persons, which are connected by friendship relations. Here is my code (getters and setters are omitted here):</p>
  
  <pre><code>@NodeEntity
  public class Person {
      @GraphId
      private Long id;
      private String name;
      private String password;
  
      @RelatedTo(type = "FRIEND_OF", direction = Direction.BOTH)
      private Set&lt;Person&gt; friends = new HashSet&lt;Person&gt;();
  
      public Person() {};
  
      public Person(String name, String password) {
          this.name = name;
          this.password = password;
      }
  
      public void befriend(Person person) {
          this.friends.add(person);
      }
  </code></pre>
  
  <p>Ultimately, I make use of the following method in order to make use of my Persons:</p>
  
  <pre><code>@Transactional
  private void populateTwoPersons() {
      Person person1 = new Person("Alice", "pw1");
      Person person2 = new Person("Bob", "pw2");
  
      List&lt;Person&gt; persons = Arrays.asList(person1, person2);
      personRepository.save(persons);
  
      person1.befriend(person2);
  
      personRepository.save(persons);
  }
  </code></pre>
  
  <p>In my understanding a friendship relation should be bidirectional, that is why I set its direction to (direction = Direction.BOTH). Now when executing the populateTwoPersons() method it results in the creation of the two person nodes, but not in an edge between them. </p>
  
  <p>Ideas that I have tried are altering the befriend()-function to</p>
  
  <pre><code>public void befriend(Person person) {
      this.friends.add(person);
      person.getFriends().add(this);
  }
  </code></pre>
  
  <p>or setting the direction of the relationship to direction = Direction.OUTGOING. This however creates a <strong>directed edge</strong>, which is not what I want.</p>
  
  <p>Why don't I get an edge in the first case altogether? Any ideas? :)</p>
  
  <p>Thanks in advance,
  Manu</p>