title: jpa one-to-many persist children with its ID
body: <p>@Entity
      public class Item {</p>
  
  <pre><code> @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column
   private Long id;
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "item")
   private List&lt;Feature&gt; features= new ArrayList&lt;Feature&gt;();
  </code></pre>
  
  <p>The Children Entity:</p>
  
  <pre><code>public class Feature{
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;
  
   private String attribute1;
   private String attribute2;
   private String featureCode;
  
      @ManyToOne
   private Item item;
  
          .....
   public String getFeatureCode() {
    if (item != null) {
     feature = item.getId() + attribute1 + attribute2;
    }
    return feature;
   }
  </code></pre>
  
  <p>You can see from my annotaiton, When Item pesist, it will also persist its children.</p>
  
  <p>As composited ID has a very bad reputation and I realy need its parent's ID in the Feature in order to easy query, I add an featureCode to append the three column together.</p>
  
  <p>My problem is , the Item's id is generated from database. From the debug information, I guess it same Item first, then update Feature's item. This causes my featureCode's item.getId() null result.</p>
  
  <p>Is it possible to change one-to-many's cascade persist behavoir, like persist Item first, then save it's children? </p>