【发布时间】:2016-03-07 10:52:57
【问题描述】:
我正在尝试使用 JPA 控制器方法从表中删除记录,但出现以下异常..
“javax.persistence.TransactionRequiredException:如果实体管理器尚未加入当前事务,则无法调用需要事务的方法。”
以下是我要运行的代码
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();
}
}
非常感谢任何帮助:)
【问题讨论】:
标签: java exception jpa persistence