title: ORA-01400: Error while inserting Foreign Key using Hibernate
body: <p>I have two tables <code>A</code> &amp; <code>B</code> with a foreign key from <code>B</code> to a called <code>FK_A</code>. I have a <strong>not null</strong> constraint on <code>FK_A</code>.</p>
  
  <p>I have the following two classes:</p>
  
  <pre><code>@Entity
  @Table(name = "A")
  public class A {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @Column(name = "ID")
      private long id;
  
      @OneToMany(cascade=CascadeType.ALL)
      @JoinColumn(name = "FK_A", nullable = true)
      private Set&lt;B&gt; b; 
  
      //getters setters etc.
  }
  
  
  @Entity
  @Table(name = "B")
  public class B {
      //attributes, getters setters etc.
  }
  </code></pre>
  
  <p>The reads work fine but when I try to write A to the DB, I get : ORA-01400: cannot insert NULL into <code>("SCHEMA"."B"."FK_A")</code></p>
  
  <p>The code I am tring to insert the entity looks something like:</p>
  
  <pre><code>@PersistenceContext(unitName = "ab")
  private EntityManager em;
  
  A a = new A();
  B b = new B();
  
  Set&lt;B&gt; bList = new HashSet();
  bList.add(b);
  a.setB(bList);
  
  em.persist(a);
  </code></pre>
  
  <p>Now if I am correct shouldn't hibernate automatically populate <code>FK_A</code> in table <code>B</code> based on the <code>id</code> it had autogenerated. If not how can I go about setting it?</p>