title: JPA cascade persist - many to one
body: <p>I have a many to one relationship and I am trying to persist a child entity.</p>
  
  <pre><code>public class Office
  {
  public int id;
  public int grades;
  @OneToMany
  public set&lt;Employee&gt; employees;
  }
  
  public class Employee{
  @GeneratedValue(strategy=GeneratedValue.identity)
  public int empid;
  @ManyToOne(cascade=cascadeType.ALL)
  public Office office;
  }
  </code></pre>
  
  <p>Office Id is already present in the database. But employee is not.
  Now if i am adding an employee and his grades must go into the office database.</p>
  
  <p>When i do the following operation,grades are not getting saved</p>
  
  <pre><code>Office office = new Office();
  office.setId(23);
  office.setGrades(5);
  employee.setOffice(office);
  em.persist(employee);
  </code></pre>
  
  <p>How to save grades into the office table in a single operation</p>