title: JPA OneToMany - List doesn't update after add/delete object, but is persisted in DB
body: <p>I'm using JPA not Hibernate. I have a Problem with my Relationship as follows. I have a 1:N Relationship (Parent:Child).</p>
  
  <p>On a JSP-Site, the Parent and the Children are displayed.
  If I load the JSP-Site (for the first time) and save a Parent with a Child, all is ok. The Parent is saved and the Child is saved too to the DB with the foreign key.</p>
  
  <p>After that, a second JSP-Site is displayed with the Parent and Children.</p>
  
  <p>But if I go back to the first Site and save a second Child (adding Child) to existing Parent, the <code>childEntityList</code> is still the old one, I mean, the new Child is not inside this List, but inserted in the database.</p>
  
  <p>Why the <code>childEntityList</code> is old and doesn't update?</p>
  
  <p>The Parent:</p>
  
  <pre><code>@Entity
  @Table(schema = "test", name = "Parent")
  @XmlRootElement
  @NamedQueries({...})
  public class Parent implements Serializable {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY, generator = "A_SEQ")
      @Basic(optional = false)
      @NotNull
      @Column(name = "ID")
      private int id;
  
      @OneToMany(mappedBy = "p", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
      private List&lt;ChildEntity&gt; childEntityList = new ArrayList&lt;ChildEntity&gt;();
      // ...
  
      public List&lt;ChildEntity&gt; getChildEntityList() {
          return childEntityList;
      }
  
      public void setChildEntityList(List&lt;ChildEntity&gt; childEntityList) {
          this.childEntityList = childEntityList;
      }
  
      public void addChildEntityToParent(ChildEntity c) {
          this.childEntityList.add(c);
          if(c.getParent() != this) {
              c.setParent(this);
          }
      }
  
      public void removeChildEntityFromParent(ChildEntity c) {
          childEntityList.remove(c);
      }
      // ...
  }
  </code></pre>
  
  <p>The Child:</p>
  
  <pre><code>@Entity
  @Table( name = "Child" )
  @NamedQueries({...})
  public class ChildEntity implements Serializable {
      @Id
      @GeneratedValue( strategy = GenerationType.IDENTITY )
      @Column( name = "CHILD_ID" )
      private Long childId;
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "PARENT_ID")
      private Parent p;
      // ...
  
      public Parent getParent() {
          return p;
      }
  
      public void setParent(Parent p) {
          this.p= p;
          if(!p.getChildEntityList().contains(this)) {
              p.getChildEntityList().add(this);
          }
      }
  </code></pre>
  
  <p>Save-Code:</p>
  
  <pre><code>Parent p = new Parent(...);
  ChildEntity c = new ChildEntity(...);
  p.addChildEntityToParent(c);
  childEntityFacade.create(c);
  </code></pre>
  
  <p>View-Code:</p>
  
  <pre><code>// ...
  public doSomething(Parent p) {
      super(p);
  }
  // ...
  List&lt;ChildEntity&gt; cList = p.getChildEntityList();
  System.out.print("Size: " + c.size());
  // ...
  </code></pre>
  
  <p>In the View-Code, the size of the <code>childEntityList</code> is every time the same even I add a Child.
  Only when I restart the server, all Children of the Parent are displayed.</p>
  
  <p>When is the <code>childEntityList</code> in the Parent Class filled?
  Is it automatically, because of the <code>@OneToMany</code>?</p>
  
  <p>Can someone explain it?</p>
  
  <p><strong>Update:</strong>
  Should I merge the EntityManager every time when I add/remove a Child object from the Parent list or have I do some other things?</p>