Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top