title: java.lang.IllegalArgumentException: Removing a detached instance com.test.User#5
body: <p>I have a java EE project using JPA (transaction-type="JTA"), hibernate as provider. I write my beans to handle the CRUD things. The program running in JBOSS 7 AS.</p>
  
  <p>I have an EntityManagerDAO :</p>
  
  <pre><code>@Stateful
  public class EntityManagerDao implements Serializable {
  
      @PersistenceContext(unitName = "dtdJpa")
      private EntityManager entityManager;
  
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public Object updateObject(Object object) {
          object = entityManager.merge(object);
          return object;
      }
  
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public void createObject(Object object) {
          entityManager.persist(object);
      }
  
      public void refresh(Object object) {
          entityManager.refresh(object);
      }
  
      public &lt;T&gt; T find(Class&lt;T&gt; clazz, Long id) {
          return entityManager.find(clazz, id);
      }
  
      @TransactionAttribute(TransactionAttributeType.REQUIRED)
      public void deleteObject(Object object) {
          entityManager.remove(object);
      }
  }
  </code></pre>
  
  <p>but when I invoke <code>deleteObject</code>, this exception comes out.</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Removing a detached instance com.test.User#5</p>
  </blockquote>
  
  <p>How is this caused and how can I solve it?</p>