title: EntityManager throws TransactionRequiredException on merge() in JBoss JSF bean
body: <p>I've set up a JSF application on JBoss 5.0.1GA to present a list of Users in a table and allow deleting of individual users via a button next to each user.</p>
  
  <p>When deleteUser is called, the call is passed to a UserDAOBean which gets an EntityManager injected from JBoss.</p>
  
  <p>I'm using the code</p>
  
  <pre><code>public void delete(E entity)
  {
      em.remove(em.merge(entity));
  }
  </code></pre>
  
  <p>to delete the user (code was c&amp;p from a JPA tutorial). Just calling em.remove(entity) has no effect and still causes the same exception.</p>
  
  <p>When this line is reached, I'm getting a TransactionRequiredException:</p>
  
  <p>(skipping apparently irrelevant stacktrace-stuff)</p>
  
  <blockquote>
    <p>...</p>
    
    <p>20:38:06,406 ERROR [[Faces Servlet]]
    Servlet.service() for servlet Faces
    Servlet threw exception
    javax.persistence.TransactionRequiredException:
    EntityManager must be access within a
    transaction   at
    org.jboss.jpa.deployment.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:155)
      at
    org.jboss.jpa.tx.TransactionScopedEntityManager.merge(TransactionScopedEntityManager.java:192)
      at
    at.fhj.itm.utils.DAOImplTemplate.delete(DAOImplTemplate.java:54)
      at
    at.fhj.itm.UserBean.delete(UserBean.java:53)
      at
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native
    Method)</p>
    
    <p>...</p>
  </blockquote>
  
  <p>I already tried to wrap a manually managed transaction (em.getTransaction().begin() + .commit() ) around it, but this failed because it is not allowed within JBoss container. I had no success with UserTransaction either. Searches on the web for this issue also turned up no similar case and solution.</p>
  
  <p>Has anyone experienced something similar before and found a solution to this?</p>