title: JPA Hibernate want lazy load to return empty collection
body: <p>I am using JPA-Hibernate at the moment and want collections to be empty until i call the associated get(). I have been trying for several days now without any success.
  The reason i want this is because i use Exterialize (or Serialize) and do not always want the collections to be there when sending the serialized string over to the client.</p>
  
  <pre><code>@Entity
  public class Thread implements Externalizable {
      static final long serialVersionUID = 9L;
  
  
  @OneToMany(mappedBy = "parentThread", fetch = FetchType.LAZY)
      @LazyCollection(LazyCollectionOption.EXTRA)
      public Collection&lt;Reply&gt; getReplies() {
          return replies;
      }
  </code></pre>
  
  <p>And here is the Reply model:</p>
  
  <pre><code>@Entity
  public class Reply implements Externalizable {
      static final long serialVersionUID = 8L;
  
      @ManyToOne
      @JoinColumn(name = "threadId", referencedColumnName = "id", nullable = false)
      public Thread getParentThread() {
          return parentThread;
      }
  </code></pre>
  
  <p>This code is what i use to serialize the model:</p>
  
  <pre><code>public static final String serialize(Serializable object) throws IOException, ClassNotFoundException {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ObjectOutputStream oos = new ObjectOutputStream( baos );
      oos.writeObject( object );
      oos.close();
      BASE64Encoder base64Encoder =  new BASE64Encoder();
      return  new String( base64Encoder.encode(baos.toByteArray()));
  }
  </code></pre>
  
  <p>This is what i use to find the thread objects</p>
  
  <pre><code>models.Thread thread = em.find(models.Thread.class, threadId);
  </code></pre>
  
  <p>If i use entityManager.find() or a query it still loads the list of replies. So to be extra clear, i would like the collection to be empty when i generate the Entity. Then if i call get() i would like it to fill up.</p>
  
  <p>The following image shows that the replies are stored in the list. They do not have any values in them whitch i presume is because lazy loading means that they are proxy entities that have not really been fetched from the database? Please correct be if i am wrong. As a side note, if it is possible to store the list as an arraylist or some other standard list implementation that would be great. I understand that JPA wants the persistentBag/persistentSet notation since they can have duplicate values which standard implementation do not allow and probably some other reasons aswell. But for serializing the model to the client it would be great not to need the libraries and they also do not seem to work with android because the SSID seem to change in the libraries when using android.</p>
  
  <p><img src="https://i.stack.imgur.com/zTXK5.png" alt="Image with returned replies"></p>
  
  <p>I really hope this is possible. Thx in advance!</p>