[英]When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit? - Follow up
See this link: When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit? 请参阅此链接: @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)何时提交?
How can B be the correct answer? B怎么能是正确的答案? I would thought that a method annotated with REQUIRES_NEW would commit before the outer, suspended transaction, continues.
我认为用REQUIRES_NEW注释的方法会在外部暂停事务之前继续提交。
I'm asking about this because I have seen strange behaviors when it comes to transactions started with requires_new from another bean in a for-loop. 我问这个是因为我遇到了奇怪的行为,当涉及到for循环中另一个bean的requires_new启动的事务时。 Like if Aby calls bob in a for-loop.
就像Aby在for循环中调用bob一样。 If one of these transactions is rolled back because of, for example a UniqueConstraintViolation, HSQLDB and db2 intermittently rolls back also the previous transactions, and intermittently only the transaction failed, and commits the others.
如果由于例如UniqueConstraintViolation而回滚其中一个事务,则HSQLDB和db2会间歇性地回滚先前的事务,并且间歇性地仅回滚事务,并提交其他事务。 And the behavior only changes when I restart my jboss.
当我重新启动jboss时,行为只会改变。 When a transaction fails and I get the behavior where also the previous transaction rolls back I also get a jdbcException: Connection closed in the next call from the loop.
当事务失败并且我得到上一个事务回滚的行为时,我也得到一个jdbcException:在循环的下一次调用中Connection被关闭。 So, first I wonder about the expected behavior of requires_new.
所以,首先我想知道requires_new的预期行为。 I'm using Hibernate, jboss 5, CMT, db2 and an in-memory HSQLDB(I've tried both 1.8 version and 2.2.9) Thank You!
我正在使用Hibernate,jboss 5,CMT,db2和内存中的HSQLDB(我试过1.8版本和2.2.9版本)谢谢!
So I found that this was the reason for the strange behavior 所以我发现这就是这种奇怪行为的原因
jboss ignores requires_new after restart jboss在重启后忽略requires_new
And in the link: 在链接中:
When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit? @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)什么时候提交?
the alternative a is the correct answer so it's the wrong answer in that post. 替代方案a是正确答案,因此该帖子中的答案是错误的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.