Commit transaction after exception - undo setRollbackOnly

℡╲_俬逩灬. 提交于 2019-12-11 18:18:28

问题


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.

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?


回答1:


The hint given in esej's comment was the solution: "Call a method on another bean annotated with REQUIRES_NEW."

Thanks




回答2:


You will 'Routine was invoked etc..' error when you attempt to start a new global transaction while the previous transaction was neither committed nor rollbacked.

In order to fix this, you should do the following:

When you catch the first exception, don't leave it up to the container to flag the transaction as 'rollback'. You have to manually flag the transaction as rollback.



来源:https://stackoverflow.com/questions/12088574/commit-transaction-after-exception-undo-setrollbackonly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!