3

See this link: When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit?

How can B be the correct answer? I would thought that a method annotated with REQUIRES_NEW would commit before the outer, suspended transaction, continues.

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. Like if Aby calls bob in a for-loop. 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. And the behavior only changes when I restart my 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. So, first I wonder about the expected behavior of 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!

Community
  • 1
  • 1
Mike
  • 443
  • 9
  • 26
  • possible duplicate of [When does @TransactionAttribute(TransactionAttributeType.REQUIRES\_NEW) commit?](http://stackoverflow.com/questions/11614364/when-does-transactionattributetransactionattributetype-requires-new-commit) – Roman C Mar 27 '13 at 19:20
  • Good question indeed, http://stackoverflow.com/questions/11614364/when-does-transactionattributetransactionattributetype-requires-new-commit seems in contradiction with http://stackoverflow.com/questions/10817838/ejb-3-0-nested-transaction-requires-new – Gab Mar 28 '13 at 07:45

1 Answers1

4

So I found that this was the reason for the strange behavior

jboss ignores requires_new after restart

And in the link:

When does @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) commit?

the alternative a is the correct answer so it's the wrong answer in that post.

Community
  • 1
  • 1
Mike
  • 443
  • 9
  • 26