title: Is it mandatory to instantiate collection fields in JPA?
body: <p>I was reading an article in which the author had implemented an Entity class like this:</p>
  
  <pre><code>@Entity
  public class Product {
  
   @OneToMany
   private List&lt;Part&gt; parts; // note the missing "= new ArrayList&lt;Part&gt;();"
  
   public Product() {
   }
  
   // getters and setters
  
  }
  </code></pre>
  
  <p>I always used to instantiate collection fields, in this case <code>parts</code>, either inline (<code>private List&lt;Part&gt; parts = new ArrayList&lt;Part&gt;();</code>) or inside the constructor because as far as I can remember not doing so would lead to all kinds of NPEs.</p>
  
  <p>I thought that things have changed in JPA 2 and now the JPA runtime automatically instantiates the field using runtime bytecode enhancement or reflection, so I gave it another try, however I still can't get it to work without instantiating the <code>parts</code> field, otherwise <code>aProduct.getParts().add(aPart)</code> would throw an NPE.</p>
  
  <p>So my question is that is it possible to make this work without instantiating the <code>parts</code> field in both of Java SE and Java EE environments using Hibernate as the provider? If so, how?</p>