• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTA query

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic