title: How to update the list after delete an item of that list
body: <p>It will take a moment for me to explain this, so please stay with me. I have table <code>NewsFeed</code> that has OneToMany relationship with itself. </p>
  
  <pre><code>@Entity
  public class NewsFeed(){
      ...
      @ManyToOne(optional=true, fetch=FetchType.LAZY)
      @JoinColumn(name="REPLYTO_ID")
      private NewsFeed replyTo;
  
      @OneToMany(mappedBy="replyTo", cascade=CascadeType.ALL)
      private List&lt;NewsFeed&gt; replies = new ArrayList&lt;NewsFeed&gt;();
  
      public void addReply(NewsFeed reply){        
         replies.add(reply);
         reply.setReplyTo(this);
      }
  
      public void removeReply(NewsFeed reply){
         replies.remove(reply);
      }
  } 
  </code></pre>
  
  <p>So you can think like this. Each feed can have a <code>List</code> of replies which are also type <code>NewsFeed</code>. Now it is very easy for me to delete the original feed and get the updated list back. All I need to do after delete is this. </p>
  
  <pre><code>feeds = scholarEJB.findAllFeed();  //This will query the db and return updated list
  </code></pre>
  
  <p>But I am having problem when trying to delete <code>replies</code> and getting the updated list back. So here is how I delete the <code>replies</code>. Inside my JSF managed bean I have</p>
  
  <pre><code>//Before invoke this method, I have the value of originalFeed, and deletedFeed set.
  //These original feeds are display inside a p:dataTable X, and the replies are
  //displayed inside p:dataTable Y which is inside X. So when I click the delete button
  //I know which feed I want to delete, and if it is the replies, I will know
  //which one is its original post
  public void deleteFeed(){
      if(this.deletedFeed != null){
          scholarEJB.deleteFeeds(this.deletedFeed); 
          if(this.originalFeed != null){
              //Since the originalFeed is not null, this is the `replies`
              //that I want to delete
              scholarEJB.removeReply(this.originalFeed, this.deletedFeed);
          }
          feeds = scholarEJB.findAllFeed();
      }        
  }
  </code></pre>
  
  <p>Then inside my EJB scholarEJB, I have </p>
  
  <pre><code>public void removeReply(NewsFeed feed, NewsFeed reply){
      feed = em.merge(feed);
      comment.removeReply(reply);
      em.persist(comment);
  }
  
  public void deleteFeeds(NewsFeed e){
      e = em.find(NewsFeed.class, e.getId());
      em.remove(e);
      em.getEntityManagerFactory().getCache().evict(NewsFeed.class); //Like fdreger suggested
  }
  </code></pre>
  
  <p>When I get out, the entity (the reply) get correctly removed from the database, but inside the <code>feeds</code> List, reference of that <code>reply</code> still there. It only until I log out and log back in that the reply disappear.</p>