I am trying to delete records from a table using JPA Controller method, but I get the following exception..
"javax.persistence.TransactionRequiredException: Cannot call methods requiring a transaction if the entity manager has not been joined to the current transaction."
Following is the code I am trying to run
public void deleteRulesofType(String ruleType) throws NotSupportedException, SystemException, Exception { EntityManager em = getEntityManager(); try { utx.begin(); Query query = em.createQuery("delete from RulesFound r where r.ruleType=:ruleType"); query.setParameter("ruleType", ruleType); query.executeUpdate(); em.flush(); utx.commit(); } catch (Exception e) { try { utx.rollback(); } catch (Exception re) { throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re); } throw e; } finally { em.close(); } } Any help is greatly appreciated :)