Spring Transactions - Prevent rollback after unchecked exceptions (RuntimeException)

随声附和 提交于 2019-12-01 22:39:14

As far as I know, as soon as a runtime exception is thrown from a transactional method and is intercepted by the transaction interceptor, the transaction is marked as rollback only. Even if this transactional method is called from another transactional method.

This makes sense to me: if the inner method can't recover from an exception, it can't recover, and an outer method shouldn't do as if nothing happened.

If you're expecting the transaction not to rollback, you could

  • make the inner method non-transactional
  • configure the inner method not to rollback on this exception
  • have two inner methods:
    • one that is transactional, and is intended to be called when there is no transaction yet, and which simply delegates to the second one
    • one which is not transactional, and is intended to be called as part of an already existing transaction
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!