You should clarify what you mean by distributed transaction.
If the transaction use different JCA connections inside the server the only thing is to have all such resources handle XA (two phase commits) correct.
Also a client can initiate the Tx if it is using the same server (you need transaction stickyness in this case).
If you mean that the Tx span different server instances, i.e. two EJB's on different servers you need to have a JTS configuration instead of the (default) JTA. There are scripts in the docs directory to change the configuration.
Thanks for replying.
Let's take this to elaborate a little.
JBoss AS is configured for JTS. One XA datasource is on dataSourceServer A and another XA datasource is on dataSourceServer B. All my EJBs are there on the same JBoss server (same node, single instance). Just for the sake of simplicity something is needed to be done on datasource A and datasource B where actionA and actionB corresponds to datasource A and datasource B respectively. Here actionA & actionB should be done as a part of one single transaction.
Now in case of BMT we can get the datasource via JNDI lookup and do the operation and complete the transaction by using TransactionManager of the JBoss or even by using XAResource and its lifecycle methods for two-phase commit.
But in case of CMT how we are going to achieve this. This is the point of confusion for me. How in case of CMT transactionManager will call the methods of two-phase commit ? How it will understand that which XA--Datasources are involved (is there any way to configure this ?) ?
1 of 1 people found this helpful
If you use CMT the container will track which resource is involved in the transaction.
If the EJB is finished (mean that the business method return) the container will send a prepare to all XA resources and if successful a commit.
It is the responsibility of the container how to do this. AFAIK JBoss will send prepare/commit in that order the resources are got from the container( but this might change with different versions).
Also if you use different resources from an EJB, or a couple of EJB's, inside the same JBoss instance you do not need a JTS configuration. It will be more complex and might have performance drawbacks as it uses IIOP.
So a Tx is committed if you return from a method with a different Tx scope, let me shown an example:
do DB stuff
-> M2 (Tx.NotSupported)
-> M3 (Tx.Required)
do DB stuff maybe different DB'S
<- (prepare)commit Tx2
The commits are done by the container outside your code (also outside the interceptors)
There is no configuration to control that.
Thanks Fink. Your reply helps.