title: JPA @ManyToMany - Cannot delete or update a parent row: a foreign key constraint fails
body: <p>I have the Entities: </p>
  
  <pre><code>@Entity
  public class User {
  
      @ManyToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
      private List&lt;Role&gt; roles = new ArrayList&lt;Role&gt;();
  </code></pre>
  
  <hr>
  
  <pre><code>@Entity
  public class Role {
  
      @ManyToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
      private Set&lt;Permission&gt; permissions = new HashSet&lt;Permission&gt;();
  </code></pre>
  
  <p>When doing a delete/remove the following Exception is thrown:</p>
  
  <pre><code>Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`user_role`, CONSTRAINT `FK_USER_ROLE_roles_ID` FOREIGN KEY (`roles_ID`) REFERENCES `role` (`ID`))
  </code></pre>
  
  <p>It seems there is an issue with the generated join table and foreign keys.</p>
  
  <p>How can this be fixed so a Role can be deleted ?</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>Exported SQL shows this:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `user_role` (
    `User_ID` bigint(20) NOT NULL,
    `roles_ID` bigint(20) NOT NULL,
    PRIMARY KEY (`User_ID`,`roles_ID`),
    KEY `FK_USER_ROLE_roles_ID` (`roles_ID`)
  )
  </code></pre>