Updating ManyToOne Object With Full Reference
<p>I have 2 Entities:</p>

<pre><code>public class Brand {

  @OneToMany(mappedBy = "brand", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
  @JsonView(Views.Detailed.class)
  @JsonManagedReference("brand-departments")
  private List&lt;Department&gt; departments;

}

public class Department {
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "brand_id", nullable = false)
  @JsonBackReference("brand-departments")
  private Brand brand;
}
</code></pre>

<p>When updating a <code>Department</code>, I'm doing the following in my controller:</p>

<pre><code>public ResponseEntity&lt;MappingJacksonValue&gt; update(@PathVariable Long brandId,
                       @Valid @RequestBody Department department, BindingResult bindingResult) throws Exception {

    if (bindingResult.hasErrors()) {
        throw new InvalidRequestException("Invalid Department", bindingResult);
    }

    Department existingDepartment = departmentService.findById(department.getId());
    BeanUtils.copyProperties(department, existingDepartment, "brand");
    this.departmentService.update(existingDepartment);
    MappingJacksonValue mappingJacksonValue = jsonView(JSON_VIEWS.SUMMARY.value, department);
    return new ResponseEntity&lt;&gt;(mappingJacksonValue, HttpStatus.OK);
}
</code></pre>

<p>The reason I ignore <code>brand</code> when copying the properties is because the brand comes in NULL for the <code>@RequestBody Department department</code>. When I look up the <code>existingDepartment</code> it has the right Brand. However, when I update the department, it fails because it says <code>BRAND_ID</code> is NULL. But I've verified that it isn't NULL.</p>

<p>If I do the following:</p>

<pre><code>public ResponseEntity&lt;MappingJacksonValue&gt; update(@PathVariable Long brandId,
               @Valid @RequestBody Department department, BindingResult bindingResult) throws Exception {

    if (bindingResult.hasErrors()) {
        throw new InvalidRequestException("Invalid Department", bindingResult);
    }

    Department existingDepartment = departmentService.findById(department.getId());
    existingBrand.setBrand(new Brand(brandId));
    BeanUtils.copyProperties(department, existingDepartment);
    this.departmentService.update(existingDepartment);
    MappingJacksonValue mappingJacksonValue = jsonView(JSON_VIEWS.SUMMARY.value, department);
    return new ResponseEntity&lt;&gt;(mappingJacksonValue, HttpStatus.OK);
</code></pre>

<p>}</p>

<p>(setting the <code>brand</code> on <code>existingDepartment</code> to just be a non-session-connected object with just an ID) the update works correctly. So there's something about the fact that <code>existingDepartment</code> has a reference to a full blown database fetched version of <code>brand</code> that is causing the update to fail, but I'm not sure why.</p>