0

I have a stateless bean, that has container for transaction management, and i have 2 separate for loops in what i add some data to the database, and in other i delete some data. After that, i run some validity check, and if it fails, i throw an exception. What is not clear to me is, if an error is thrown, why is transaction not rolled back? I tried throwing a custom exception at first, then a RollbackException, but the result is the same - rollback is not done. Is it possible that Jboss is overriding some of mine settings, or am I missing out on some other part?

Also, i was wondering what is considered "a transaction" in stateless bean, that is container managed? Is it everything inside a method, or could one method contain more than one transaction?

Nikola Ivkov
  • 89
  • 1
  • 10

2 Answers2

1

if an error is thrown, why is transaction not rolled back?

Because that is what the specification says. Any RuntimeExceptions or checked exceptions marked with @ApplicationException are rolled back.

Also, i was wondering what is considered "a transaction" in stateless bean, that is container managed? Is it everything inside a method, or could one method contain more than one transaction?

All EJB methods per default join a transaction. If none is available a new one is created. You can have more than one transaction when you call an EJB method with REQUIRES_NEW. Just remember this will be an independent transaction, not a subtransaction. See @TransactionAttribute for more information.

Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52
0

JBoss has some dreadful default in the Datasouce configuration. Datasources created in JBoss are not JTA - in admin console the Use JTA setting is unchecked and in xml related setting is <datasource jta="false" .... Check if changing it to jta="true", will not solve your issue.

Check this Transactions don't rollback for some more details.

Community
  • 1
  • 1
Gas
  • 17,601
  • 4
  • 46
  • 93
  • This looks like a possible solution, but i won't have time to test it before tomorrow :) I will let you know if it helps – Nikola Ivkov Aug 31 '15 at 14:26