title: Entity must be managed to call remove when I try to delete an entity
body: <p>I have this method to delete the entity selected in the list. but when called generates this error and I can not see why.</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Entity must be managed to call
    remove: HP Envy 15, try merging the detached and try the remove again.</p>
  </blockquote>
  
  <pre><code>public void delete(Stock stock){
          EntityManager em = ConnectionFactory.createEntityManager();
          em.getTransaction().begin();
          em.detach(stock);
          em.remove(stock);
          em.getTransaction().commit();        
          em.close();
      }
  </code></pre>
  
  <p>I've read other related posts</p>
  
  <p><a href="https://stackoverflow.com/questions/9338999/entity-must-be-managed-to-call-remove">Entity must be managed to call remove</a></p>
  
  <p><a href="https://stackoverflow.com/questions/22602923/illegalargumentexception-entity-must-be-managed-to-call-remove">IllegalArgumentException: Entity must be managed to call remove</a></p>