title: Open JPA Saving OneToMany , foreign key not set
body: <p>I've two tables: TaStock and TaStockPrice. Field tastockid in table TaStockPrice is the foreign key to table TaStock. </p>
  
  <pre><code>@Entity
  public class TaStock {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Integer id
  
      @OneToMany(mappedBy = "taStock", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
      private List&lt;TaStockPrice&gt; tastockpriceList;
  
      public void addTaStockPrice(TaStockPrice taStockPrice) {
         if (taStockPrice == null) {
             return;
         }
         taStockPrice.setTaStock(this);
         if (tastockpriceList == null) {
             tastockpriceList = new ArrayList&lt;TaStockPrice&gt;();
             tastockpriceList.add(taStockPrice);
         } else if (!tastockpriceList.contains(taStockPrice)) {
             tastockpriceList.add(taStockPrice);
         }
      }
      ....
  }
  
  
  
  @Entity
  public class TaStockPrice {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      Integer id
      @Column
      private Integer tastockid;
  
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "tastockid", nullable = false, updatable = false, insertable = false)
      private TaStock taStock;
      ...
  }
  </code></pre>
  
  <p><strong>persisting taStock with Children</strong></p>
  
  <pre><code>@Test
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public void createTaStock() throws Exception {
      TaStock taStock = new TaStock();
               ...
  
      TaStockPrice taStockPrice = new TaStockPrice();
               ...
  
      taStock.addTaStockPrice(taStockPrice);
      taStockService.persist(taStock);
  }
  </code></pre>
  
  <p>I read that when persisting a parent class, hibernate automatically persist the children of that class. But instead, the following exception occurs:</p>
  
  <p>javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: ERROR: null value in column "tastockid" violates not-null constraint</p>