title: JPA Updating Bidirectional Association
body: <p>Lets assume we have the following Entities: </p>
  
  <pre><code>    @Entity
      public class Department {
  
          @OneToMany(mappedBy="department")
          private List&lt;Employee&gt; employees;
      }
  
      @Entity
      public class Employee {
  
          @ManyToOne
          private Department department
      }
  </code></pre>
  
  <p>It is understandable on an update that we need to maintain both sides of the relationship as follows:</p>
  
  <pre><code>Employee emp = new Employee();
  Department dep = new Department();
  emp.setDepartment(dep);
  dep.getEmployees().add(emp);
  </code></pre>
  
  <p>All good up till now. The question is should I apply merge on both sides as follows, and an I avoid the second merge with a cascade?</p>
  
  <pre><code>entityManager.merge(emp);
  entityManager.merge(dep);
  </code></pre>
  
  <p>Or is merging the owning side enough? Also should these merges happen inside a Transaction or EJB? Or doing it on a simple controller method with detached entities is enough?</p>