title: Hibernate, JPA cant delete one-to-many relation
body: <p>I have one-to-many relation:</p>
  
  <pre><code>@Entity
  @Table(name = "Users")
  public class User {
  
      @Id
      @Column(name = "user_id", nullable = false)
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
  
      @Column(name = "login", nullable = false)
      private String login;
  
      @Column(name = "password", nullable = false)
      private String password;
  
      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "role_id", nullable = false)
      private Role role;
  
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = javax.persistence.CascadeType.ALL)
      private Set&lt;Contacts&gt; contacts = new HashSet&lt;Contacts&gt;();
  </code></pre>
  
  <p>And I'm trying to delete <code>User</code> object with all Contacts; I tried to use:</p>
  
  <ol>
  <li><code>cascade = javax.persistence.CascadeType.ALL</code> </li>
  <li><p><code>cascade =
      javax.persistence.CascadeType.REMOVE</code></p></li>
  <li><p><code>@Cascade(CascadeType.DELETE)</code> from <code>org.hibernate.annotations</code></p></li>
  <li><p><code>@Cascade(CascadeType.DELETE_ORPHAN)</code> from <code>org.hibernate.annotations</code></p></li>
  </ol>
  
  <p>but nothing helped. I always get exception:</p>
  
  <blockquote>
    <p>org.hibernate.util.JDBCExceptionReporter - Cannot delete or update a
    parent row: a foreign key constraint fails
    (<code>contactmanager</code>.<code>contact</code>, CONSTRAINT <code>contact_ibfk_1</code> FOREIGN KEY
    (<code>user_id</code>) REFERENCES</p>
  </blockquote>
  
  <p><strong>UPD</strong>
  Code that deletes a User is as follows:</p>
  
  <pre><code>@Transactional
  public void removeUser(User user) {
      sessionFactory.getCurrentSession().delete(user);
  }
  </code></pre>
  
  <p>I'll appreciate any help! Thanks.</p>