简体   繁体   English

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)什么时候提交? - 跟进

[英]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.

相关问题 javax @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)有条件? - javax @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) with condition? @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)为提交事务占用了太多时间 - @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) taking way too much time for commit transaction Hibernate 和 EJB:如何正确使用 @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)? - Hibernate and EJB: how to correctly use @TransactionAttribute(value = TransactionAttributeType.REQUIRES_NEW)? 什么时候JPA REQUIRES_NEW事务提交确实 - When exactly does JPA REQUIRES_NEW transaction commit TransactionAttributeType.NOT_SUPPORTED 对检索实体有意义吗? - Does TransactionAttributeType.NOT_SUPPORTED make sense for retrieving entities? Wildfly - @TransactionAttribute - - Wildfly - @TransactionAttribute - Propagation.REQUIRES_NEW 不会在 Spring 中使用 JPA 创建新事务 - Propagation.REQUIRES_NEW does not create a new transaction in Spring with JPA Hibernate需要begin和commit才能读取 - Hibernate requires begin and commit for read 为什么OpenEntityManagerInViewFilter更改@Transactional传播REQUIRES_NEW行为? - Why does OpenEntityManagerInViewFilter change @Transactional propagation REQUIRES_NEW behavior? 何时使用@Transactional 的propagation=Proagation.REQUIRES_NEW? - When to use @Transactional's propagation=Proagation.REQUIRES_NEW?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM