title: Cannot Delete parent row with JPA @OneToMany Relationship
body: <p>In my Java EE application, I have two persistent entities <code>Worklist</code> and <code>Task</code> with these JPA relationships:</p>
  
  <p><code>Worklist</code> entity:</p>
  
  <pre><code> public class WorkList implements Serializable {
      ...
      @OneToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE} , mappedBy ="worklist")
      private List&lt;Task&gt; tasks;
      ...
      }
  </code></pre>
  
  <p>And the <code>Task</code> entity:</p>
  
  <pre><code>  public class Task implements Serializable {
      ...
      @ManyToOne
      private WorkList worklist;
      ...
      }
  </code></pre>
  
  <p>I indicated the cascade type in <code>Worklist</code> as:</p>
  
  <pre><code>  cascade={CascadeType.PERSIST, CascadeType.REMOVE}
  </code></pre>
  
  <p>So, I can persist a <code>Worklist</code> and a list of <code>tasks</code> that are associated to this <code>Worklist</code> but I have a problem when I try to delete a <code>Worklist</code> and I have this exception: </p>
  
  <pre><code>Avertissement: Local Exception Stack: 
  Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461):  
  org.eclipse.persistence.exceptions.DatabaseException
  Internal Exception:  
  com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot  
  delete or update a parent row: a foreign key constraint fails (`scopedata`.`TASKS`, 
  CONSTRAINT `FK_TASKS_WORKLIST_id` FOREIGN KEY (`WORKLIST_id`) REFERENCES `WORKLISTS` 
  (`id`))
  Error Code: 1451
  Call: DELETE FROM WORKLISTS WHERE ((id = ?) AND (version = ?))
  bind =&gt; [2 parameters bound]
  Query: DeleteObjectQuery(WokList{id=bbf05bdb-1314-4b07-9f4e-69898b800c00, creation=Thu
  Nov 28 08:39:21 CET 2013, startDate=Thu Nov 07 00:00:00 CET 2013, endDate=Fri Nov 15
  00:00:00 CET
  </code></pre>
  
  <p>On the other side, I can successfully delete a <code>Task</code>.</p>
  
  <p>This is the methode in the WorklistManager.java that removes a worklist</p>
  
  <pre><code>   @Override
       public boolean deleteWorkList(WorkList workList) {
         if (findWorkList(workList)) {
          em.remove(em.merge(workList));
          return true;
      }
      return false;
      }
  </code></pre>
  
  <p>Then, I call this methode in the Managed Bean:</p>
  
  <pre><code>    public String deleteWorkList() {
      workListManagerLocal.deleteWorkList(selectedWorkList);
      return "index";
    }
  </code></pre>
  
  <p>I am working with: <code>JPA2</code> and <code>Glassfish 3.1.2.2</code>.</p>