Reputation: 89
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?
Upvotes: 0
Views: 1455
Reputation: 4604
if an error is thrown, why is transaction not rolled back?
Because that is what the specification says. Any RuntimeException
s 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.
Upvotes: 1
Reputation: 18020
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.
Upvotes: 0