0

Is the complete programming of BMT based on UserTransaction interface? In other words, if I want to use BMT, is there any scenario when I would require more services than those provided by the UserTransaction interface.

Why this question? If I use a different implementation of the transaction manager (such as Bitronix TM or Atomikos) and not the default provided by the container, is it just enough to inject the new TM into UserTransaction object?

-Thanks

Bala
  • 1,193
  • 2
  • 12
  • 34

2 Answers2

2

This is really limited to what the app server itself will allow; i.e. if it explicitly supports replacing the transaction manager.

The real art to transaction management is the container registering transactional resources (DataSource connections, JMS Sessions, JPA EntityManagers, etc) with the TransactionManager via wrapping them with Synchronization objects and registering them with the current transaction via either the Transaction or the TransactionSynchronizationRegistry

The container implements the Synchronization objects, the TransactionManager implements the Transaction and TransactionSynchronizationRegistry objects. The coordination between the two is what gives you actual management when a transaction is running.

BMT and CMT are just alternate ways to tell the container to start/stop transactions. In some regards the term "Bean-Managed" is false as the UserTransaction in every compliant app server will be implemented by the container and thus it is still the container doing the work. As well "Container-Managed" is slightly misleading as it is still the bean developer deciding when transactions are started/stopped, it's just done declaratively vs programmatically. The most accurate description of these features would be Programmatically-Managed Transactions and Declaratively-Managed Transactions. In all cases it is still the bean talking with the container and the container and transaction manager doing all the work.

All that said it may still be possible for you to change the transaction manager, OpenEJB and TomEE support it, however it will not work in the way you are attempting. Check with your vender to see if this is possible.

David Blevins
  • 19,178
  • 3
  • 53
  • 68
  • Thanks for the reply. Could you please explain more on _"however it will not work in the way you are attempting."_ In my case, I am not replacing the TM in the container, but I am just using the 3rd party TM in the unit testing phase when there is no container involved. I just want to know if BMT can be achieved fully using the services of UserTransaction interface or do we need some other services for any special scenario? (like for eg. Dexter has explained that it is possible to use BMT without UserTransaction in resource local TM). – Bala Jan 03 '12 at 09:35
0

Maybe not entirely answering your question, but if using BMT you are also allowed to use resource local transaction managers. In that case you would not use the (injected) UserTransaction interface.

Do note that this is only legal if no transaction is in progress that is started via the said UserTransaction interface.

Bala
  • 1,193
  • 2
  • 12
  • 34
dexter meyers
  • 2,798
  • 2
  • 18
  • 22
  • Thanks for your answer. Could you please illustrate it with a simple example. Do you mean to say that while using resource local TM there is no need of UserTransaction? If I am not mistaken, I guess it is possible to use UserTransaction in such cases although we will not be using JTA compliant transactions. Please correct me if I am wrong. – Bala Jan 02 '12 at 15:12
  • UserTransaction is JTA compliant, if I'm not mistaken by definition. To be sure, a resource local TM is simply something like `connection.setAutocommit(false)` on a JDBC connection. – dexter meyers Jan 02 '12 at 15:57