title: Hibernate OneToMany generated foreign key
body: <p>I have the following table structure:</p>
  
  <pre><code>parent(parentId)
  child(childId, parentId fk)
  </code></pre>
  
  <p>Then, I have the following objects:</p>
  
  <pre><code>@Entity
  @Table(name = "parent")
  public class Parent {
     @Id
     @GeneratedValue(...)
     private String id;
  
     @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
     @JoinColumn(name = "parentId")
     Set&lt;Child&gt; children
  }
  
  @Entity
  @Table(name = "child")
  public class Child {
     @Id
     @GeneratedValue(...)
     private String id;
  
     @Column(...)
     private String parentId;
  
  }
  </code></pre>
  
  <p>Now, I create a transient parent and child, and I add the child to the parent, then save the parent:</p>
  
  <pre><code>Parent parent = new Parent();
  parent.children.add(new Child());
  
  parentDao.save(parent);
  </code></pre>
  
  <p>I get the exception:</p>
  
  <pre><code>org.hibernate.PropertyValueException: not-null property references a null or transient value
  </code></pre>
  
  <p><strong>My question:</strong> How can I get the parentId in the child class to automatically be set to the value generated by the insertion of the parent?</p>