title: JPA: How to delete link record in unidirectional many to many relationship?
body: <p>I have an unidirectional many to many mapping for entity 'Activity' and 'Invoice'. The mapping is set in Activity entity only( I don't need access activity from Invoice side).</p>
  
  <pre><code>@ManyToMany
  @JoinTable(name = "OP_ACTIVITY_INVOICE_XREF", joinColumns = @JoinColumn(name = "ACTIVITY_ID", referencedColumnName = "OBJECT_ID"), inverseJoinColumns = @JoinColumn(name = "INVOICE_ID", referencedColumnName = "OBJECT_ID"))
  private Set&lt;Invoice&gt; invoices;
  </code></pre>
  
  <p>The insert and update are working fine, but I am having problem with deleting activity. The deleting activity code is as below:</p>
  
  <pre><code>    activity.getInvoices().clear();
      em.remove(activity);
  </code></pre>
  
  <p>when I run these code, I thought the em will delete the record from join table first, then delete activity record (invoice records should remain untouched). but the record in join table never get deleted. I am getting this foreign key error:</p>
  
  <pre><code>[STDOUT] Hibernate: delete from OP_ACTIVITY where OBJECT_ID=?
  [JDBCExceptionReporter] SQL Error: 1451, SQLState: 23000 
  ERROR [JDBCExceptionReporter] Cannot delete or update a parent row: a foreign key constraint fails (`prod/op_activity_invoice_xref`.......
  </code></pre>
  
  <p>What am I doing wrong here? please help, thanks.</p>