title: Hibernate replaced PersistentBag with ArrayList is returned back again in the same request
body: <p>In a backing bean <code>edit()</code> method, I have the following code</p>
  
  <pre><code>public void edit(Entity e) {
      this.entity = entityService.find(e);
      this.entity.setLazyList(new ArrayList(this.entity.getLazyList()));
  }
  public Entity getEntity() {
      return this.entity;
  }
  </code></pre>
  
  <p>As it's shown, I initialized lazy list by changing it with my own <code>ArrayList</code>. <strong>The strange thing is that the <code>PersistentBag</code> inside lazy list is returned back as soon as it exists <code>edit()</code> method</strong>. What I did to find this behavior:</p>
  
  <ol>
  <li>Put a break point in edit method. After find, I see JVM ID of founded entity, say it's 101.</li>
  <li>Put a break point in <code>getEntity()</code> method. After <code>edit()</code> exists, <code>getEntity()</code> is called, and JVM ID of entity is still 101, but <code>entity.lazyList</code> has <code>PersistentBag</code> instead of <code>ArrayList</code>.</li>
  </ol>
  
  <p>My LazyList is bound to a . This PersistentBag then causes LazyInitializationException when I press save button in my JSF page. Exception is thrown (before save() method in the backing bean is called) because of from this part of Mojarra (also tested with MyFaces, it also throws exception):</p>
  
  <p><em>MenuRenderer, line: 365</em></p>
  
  <pre><code>// No cloned instance so if the modelType happens to represent a
  // concrete type (probably not the norm) try to reflect a
  // no-argument constructor and invoke if available.
  if (targetCollection == null) {
      //noinspection unchecked
      targetCollection =
            createCollection(currentValue, modelType);
  }
  </code></pre>
  
  <p>Since <code>currentValue</code> is unfortunately a PersistentBag (and also initialized), createCollection() returns a new instance of this object which doesn't know session and loaded objects anymore.</p>