Forums Register Login

JTA query

+Pie Number of slices to send: Send
Hi,

I am new to JTA. I was going through JTA examples and I could see 2 ways to use JTA in my application client code for distributed transactions.

1. By getting UserTransaction from EJB container.
and

2. By retrieving XAResource.
I am not sure when to use which code.
Is it that in case of EJBs I need to use first approach and for rest I should use second one.

Thanks.
+Pie Number of slices to send: Send
EJBs allow you to choose between Container Managed Transactions (CMT) and Bean Managed Transactions (BMT).

In case of CMT, its the container which manages the transactions (i.e. begin/commit/rollback) on the bean methods. EJBs allow you to mark individual methods on the beans to have specific transaction attributes. A bean developer can mark a bean method as having transaction attribute of REQUIRED (there are many other transaction attribtues available). When this method on the bean is invoked, the container will then create a new transaction (if there's no transaction in progress currently) or add this method to the currently running transaction. Any transaction aware resources (like datasources) which are used as part of this method will then be tracked within this transaction context by the container.

On the other hand, BMT leaves it to the bean developer to manage transactions (begin/commit/rollback). The first piece of code in your post is an example for BMT, where you are starting/commiting the transaction.

So the real question is - do you want CMT or BMT for your beans. Also, are you using EJB3 or EJB2.x. Based on the version, there are different ways to configure the transaction attributes on the bean methods.
+Pie Number of slices to send: Send
Patrio JS,

Please check your private messages, by clicking on the "My Private Messages" link on top of this page, for a message from JavaRanch.
What a show! What atmosphere! What fun! What a tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2061 times.
Similar Threads
Understanding JTA internals
JTA Problem--The Xid is not valid
Transaction: Spring2.x + Hibernate3.0 + Jboss + Multiple Databases
XA DataSource configuration Error/Exception in JBoss
JTA Code
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 00:37:00.