且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring中发生异常时的事务回滚

更新时间:2023-09-29 13:03:40

如果您正在使用休眠模式,请考虑这种情况。

If you're using hibernate, think of this scenario.

repoMember.save (A,B);执行完毕后,休眠会话尚未刷新会话(即执行保存SQL)util createMember()完成。当休眠实际上刷新并执行保存sql时,就会发生该错误。这就是为什么您可能无法捕获导致事务回滚的异常的原因。

When repoMember.save(A,B); is executed, hibernate session hasn't flushed the session (i.e., executes save sql) util createMember() is finished. When hibernate actually flushes and executes the save sql, that error occurs. That's why you might not able to catch that exception which causes your transaction rollback.

以下链接可能会有所帮助
http://hedleyproctor.com/2014/08/understanding-hibernate-session-flushing/

here is link that might be helpful http://hedleyproctor.com/2014/08/understanding-hibernate-session-flushing/