title: Spring Data Rest - PUT is not working for associated reference types?
body: <p>I have the following domain class implemented for a Spring Data Rest project.</p>
  
  <pre><code>@Entity
  @Data
  public class Address {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private long addressID;
  
      private String houseName;
  
      private String apartmentNumber;
  
      @ManyToOne
      private City city;
  
      @ManyToOne
      private Country country; 
  
  }
  </code></pre>
  
  <p>Now I am creating an Address resource by sending a POST with following JSON.</p>
  
  <pre><code>{   
      "houseName":"Some House",
      "apartmentNumber":"13 B",
      "city": "http://localhost:8080/city/1"
      "country":"http://localhost:8080/countries/1"
  }
  </code></pre>
  
  <p>When I send a PUT request to the endpoint <code>http://localhost:8080/addresses/1</code> with the following JSON, the values for houseName is updated. However the city remains unchanged even though I am sending a different URI for the city.</p>
  
  <pre><code>{   
      "houseName":"Another House",
      "apartmentNumber":"13 B",
      "city": "http://localhost:8080/city/2"
      "country":"http://localhost:8080/countries/1"
  }
  </code></pre>
  
  <p>If I send a PATCH instead of PUT the city value is also updated. So how do I fix this?</p>
  
  <p><strong>UPDATE 1</strong></p>
  
  <p>Country class</p>
  
  <pre><code>@Data
  @Entity
  public class Country {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long countryID;
  
      private String countryName;
  
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "country", orphanRemoval = true)
      private List&lt;City&gt; cities;
  
  }
  </code></pre>
  
  <p>City class</p>
  
  <pre><code>@Data
  @Entity
  public class City {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private long cityID;
  
      private String cityName;
  
      @ManyToOne
      @JoinColumn(name = "country_id")
      private Country country;
  }
  </code></pre>