javax.persistence.TransactionRequiredException:
javax.persistence.TransactionRequiredException:
我正在尝试使用 JPA Controller 方法从 table 中删除记录,但出现以下异常..
"javax.persistence.TransactionRequiredException: Cannot call methods requiring a transaction if the entity manager has not been joined to the current transaction."
以下是我正在尝试的代码 运行
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();
}
}
非常感谢任何帮助:)
尝试通过调用
让您的实体管理器加入交易
em.joinTransaction();
我正在尝试使用 JPA Controller 方法从 table 中删除记录,但出现以下异常..
"javax.persistence.TransactionRequiredException: Cannot call methods requiring a transaction if the entity manager has not been joined to the current transaction."
以下是我正在尝试的代码 运行
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();
}
}
非常感谢任何帮助:)
尝试通过调用
让您的实体管理器加入交易em.joinTransaction();