title: How does the JPA CascadeType.PERSIST work ?
body: <p>In my example, <code>Employee</code> has an <code>OneToOne</code> relationship to <code>Department</code> with <code>CascadeType.PERSIST</code>.
  When I persist multiple <code>Employee</code>,</p>
  
  <hr>
  
  <p>Why does the <code>EntityManager</code> persist a single <code>Department</code> record for all <code>Employee</code> records?</p>
  
  <hr>
  
  <p>My expectation is, if we use <code>CascadeType.PERSIST</code>, when an <code>Employee</code> is being persisted, a <code>Department</code> record will be created anew for each <code>Employee</code> record.</p>
  
  <p>Employee.java</p>
  
  <pre><code>@Entity
  public class Employee {
      private String id;
      private String name;
      @OneToOne(cascade = CascadeType.PERSIST)
      @JoinColumn(name = "DEP_ID", referencedColumnName = "ID")
      private Department department;
  
      -----
  }
  </code></pre>
  
  <p>Department.java</p>
  
  <pre><code>@Entity
  public class Department implements Serializable {
      private String id;
      private String name;
  }
  </code></pre>
  
  <p>Test.java</p>
  
  <pre><code>public void insert() {
      em = emf.createEntityManager();
      em.getTransaction().begin();
      Department department = new Department("Test Department");
      for(int i=1; i &lt;= 10; i++) {
          Employee e = new Employee("EMP" + i, department);
          em.persist(e);
      }
      em.getTransaction().commit();
      em.close();
  }
  </code></pre>
  
  <p>Result : </p>
  
  <pre><code>Employee Table          Department Table
  =================       ==============================
  ID  Name  DEP_ID        ID      NAME    
  =================       ==============================
  1   EMP1    1           1       Test Department
  2   EMP2    1
  3   EMP3    1
  4   EMP4    1
  5   EMP5    1
  6   EMP6    1
  7   EMP7    1
  8   EMP8    1
  9   EMP9    1
  10  EMP10   1   
  </code></pre>