File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes JTA query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JTA query" Watch "JTA query" New topic
Author

JTA query

Patrio Jensen
Greenhorn

Joined: Feb 20, 2009
Posts: 10
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.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

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.

[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTA query