I would like to clarify transaction behaviour in Jboss AS 7.1.1.
We have an application where all transactions are managed by container.
- A message driven is doing some job. It is container managed which means that it starts Transaction (T1) - this is top level transaction
- Within its processing it invokes stateless EJB business method (B2) annotated by @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW).
Transaction T2 is started at the moment. It changes some data in object "A" using injected stateless DAO EJB. The businesss method ends which means that T2 is commited.
- Data changed in "A" object within T2 are visible in MDB (T1) when T2 ends.
- T1 invokes another business method B3 - new transaction T3 is started again @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW). Within this transaction data changed in object "A" are not visible. The orignal value is populated there.
- All changes made in T1, T2, T3 are persisted to database when T1 commits. Which means that T2 and T3 are nested to T1.
Please could you clarify that
- this is corect behaviour. I beleive so. I found this article:
11.1.4. Nested Transactions
You do not need to do anything special to nest transactions. If an action is begun while another action is running, it is automatically nested. This provides a modular structure to applications,meaning that the programmer of the object does not need to be concerned about whether the applications to use the object are also transactional.
If a nested action is aborted then all of its work is rolled back. However, strict two-phase locking means that any locks the terminating transaction holds are retained until the top-level action commits or aborts. If a nested action commits, the work it has performed is only committed by the system if the top-level action commits. If the top-level action aborts, all the work is rolled back.
Committing or aborting a nested action does not automatically affect the outcome of its parent action. You can choose to implement this behavior programmatically, controlling the way faults are contained or work is undone, for instance.
- is it possible to make data changed in "A" visible to T3?
- how can I create independet Top - level transactions. It should be somehow possible. From the article above:
11.1.6. Independent Top-Level Transactions
In addition to normal top-level and nested transactions, JBoss Transaction Service also supports independent top-level actions, which you can use to relax strict serializability in a controlled way. You can execute an independent top-level action from anywhere within another transaction, and it behaves exactly like a normal top-level action. Its results are made permanent when it commits and are not undone if any of its parent actions abort
I forgot to menton that the application is using XA datasource, JPA (Hibernate).