title: Foreign key constraint issue for One-to-Many unidirectional relation
body: <p>I have <code>Employee</code> (parent) and <code>Emp_Contacts</code> (child). Only <code>Employee</code> class has unidirectional mapping. </p>
  
  <pre><code>import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.OneToMany;
  import javax.persistence.Table;
  import javax.validation.constraints.Digits;
  import javax.validation.constraints.NotNull;
  import javax.validation.constraints.Size;
  
  import org.hibernate.validator.constraints.NotEmpty;
  
  @Entity
  @Table(name="EMPLOYEE")
  public class Employee {
  
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
  
    @Size(min=3, max=50)
    @Column(name = "NAME", nullable = false)
    private String name;
  
  ...
  
    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "emp_id")
    private Set&lt;Emp_Contacts&gt; contacts;
  
  ...getters and setters...
  </code></pre>
  
  <p>My <code>Emp_Contacts</code> is as follows:</p>
  
  <pre><code>@Entity
  @Table(name = "Emp_Contacts")
  public class Emp_Contacts implements Serializable {
  
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int emp_contact_id;
  
    @NotNull
    @Column(name = "emp_id")
    private long emp_id;
  
  ....
  </code></pre>
  
  <p>DB table has not null FK constraint for <code>emp_contacts</code> table on <code>emp_id</code>.</p>
  
  <ol>
  <li>If I remove above constraint then <code>persist(employee)</code> will persists employee and corresponding emp_contacts.</li>
  <li><p>With FK constraint I get below error: </p>
  
  <p><code>MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails</code></p></li>
  </ol>
  
  <p>I searched on internet and found this link <a href="https://forum.hibernate.org/viewtopic.php?f=1&amp;t=995514" rel="noreferrer">https://forum.hibernate.org/viewtopic.php?f=1&amp;t=995514</a></p>
  
  <p>But if I put nullable in <code>Employee</code>:</p>
  
  <pre><code>@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinColumn(name = "emp_id", nullable = false)
  private Set&lt;Emp_Contacts&gt; contacts
  </code></pre>
  
  <p>my server does not even start, I get below error:</p>
  
  <pre><code>Repeated column in mapping for entity: com.cynosure.model.Emp_Contacts
  column: emp_id (should be mapped with insert="false" update="false")
  </code></pre>
  
  <p>What am I doing wrong ?</p>