异常后提交事务 - 撤消setRollbackOnly [英] Commit transaction after exception - undo setRollbackOnly
问题描述
在使用 @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
的方法中,有时会发生 org.eclipse.persistence.exceptions.DatabaseException
由于 SQLException
。我捕获此异常并通过另一个数据库查询处理该情况。但是,此查询无法通过,因为异常,setRollbackOnly会自动设置,此时我无法再提交事务。
Within my method with @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
there can sometimes happen a org.eclipse.persistence.exceptions.DatabaseException
due to an SQLException
. I catch this exception and handle the situation by another database query. However, this query does not get through, as due to the exception, setRollbackOnly is automatically set and I am unable to commit the transaction any more at this point.
在Java中SE我会做一个明确的
In Java SE I'd do an explicit
manager.getTransaction().rollback();
manager.getTransaction().begin();
但在应用程序服务器中这当然不起作用。
but within the application server this is not working of course.
我可以以某种方式让我的数据库更改在这种情况下提交吗?
Can I somehow get my database changes to commit in this situation?
推荐答案
esej评论中给出的提示是解决方案:
在另一个用REQUIRES_NEW注释的bean上调用方法。
The hint given in esej's comment was the solution: "Call a method on another bean annotated with REQUIRES_NEW."
谢谢
这篇关于异常后提交事务 - 撤消setRollbackOnly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!