title: Transaction required exception on execute update for JPQL update query
body: <p>I get this error when I try to run this code.</p>
  
  <p>Error:</p>
  
  <p>javax.persistence.TransactionRequiredException: executeUpdate is not supported for a Query object obtained through non-transactional access of a container-managed transactional EntityManager </p>
  
  <p>Code:  (_ut is a UserTransaction object)</p>
  
  <p>public void setMainCategory(Integer deptId, Integer catId) {</p>
  
  <pre><code>        try {
              Query setmain = _entityManager.createNamedQuery("Category.setAsMain");
              Query removeMain = _entityManager.createNamedQuery("Category.removeMain");
              setmain.setParameter("categoryId", catId);
              Department d;
              d=_entityManager.find(Department.class, deptId);
              removeMain.setParameter("department", d);
              _ut.begin();
              removeMain.executeUpdate();
              _ut.commit();
              _ut.begin();
              setmain.executeUpdate();
              _ut.commit();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>I have other functions that are identical in implementation and they do not throw this error.  </p>
  
  <p>Any suggestions would be greatly appreciated.</p>
  
  <p>Thanks.</p>