title: JPA: question about merging an entity before removing it
body: <p>I know I have to merge the entity before removing it, but I never thought I have to do it inside EJB. First I have these:</p>
  
  <pre><code>e = (Event) scholarBean.merge(e);
  scholarBean.remove(e);
  </code></pre>
  
  <p>in my managed bean. It give me this error</p>
  
  <pre><code>java.lang.IllegalArgumentException: Entity must be managed to call remove: com.scholar.entity.Event@998, try merging the detached and try the remove again.
  </code></pre>
  
  <p>So then I bring those two lines inside my session bean, and it works. Any idea why?</p>
  
  <p><code>Managed Bean</code></p>
  
  <pre><code>myEJB.deleteEvent(e);
  </code></pre>
  
  <p>and</p>
  
  <p><code>myEJB.java</code></p>
  
  <pre><code>public void deleteEvent(Event e){
      e = (Event) merge(e);
      em.remove(e);
  }
  </code></pre>