title: How to maintain bi-directional relationships with Spring Data REST and JPA?
body: <p>Working with Spring Data REST, if you have a <code>OneToMany</code> or <code>ManyToOne</code> relationship, the PUT operation returns 200 on the "non-owning" entity but does not actually persist the joined resource.</p>
  
  <p>Example Entities:</p>
  
  <pre><code>@Entity(name = 'author')
  @ToString
  class AuthorEntity implements Author {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id
  
      String fullName
  
      @ManyToMany(mappedBy = 'authors')
      Set&lt;BookEntity&gt; books
  }
  
  
  @Entity(name = 'book')
  @EqualsAndHashCode
  class BookEntity implements Book {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Long id
  
      @Column(nullable = false)
      String title
  
      @Column(nullable = false)
      String isbn
  
      @Column(nullable = false)
      String publisher
  
      @ManyToMany(fetch = FetchType.LAZY, cascade = [CascadeType.ALL])
      Set&lt;AuthorEntity&gt; authors
  }
  </code></pre>
  
  <p>If you back them with a <code>PagingAndSortingRepository</code>, you can GET a <code>Book</code>, follow the <code>authors</code> link on the book and do a PUT with the URI of a author to associate with. You cannot go the other way.</p>
  
  <p>If you do a GET on an Author and do a PUT on its <code>books</code> link, the response returns 200, but the relationship is never persisted. </p>
  
  <p>Is this the expected behavior?</p>