This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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

how to check transaction already started or not

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Is it possible to check in CMP any bean (session,entity) that transaction is already started by client(or in previous bean method,like if BEAN B method is called by BEAN A method) or not ?

Regards,

James
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This scenario can only apply for a CMT bean (because a BMT bean will always create its own transaction).

There is no isRunningInCurrentTransaction() method, but you can nevertheless get some some information.

If the transaction attribute is Mandatory and the method is called without an existing transaction context, the Container must throw javax.transaction.TransactionRequiredException to a remote client or javax.ejb.TransactionRequiredLocalException to a local client.

If the transaction attribute is Never and the method is called with an existing transaction context, the Container must throw java.rmi.RemoteException to a remote client or javax.ejb.EJBException to a local client.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In CMT bean, the txn attribute is specified in DD and container manages txn for bean. one can check whether current txn is destined for rollback by calling boolean ejbcontext.getRollbackOnly(). there is no method to my knowledge that will tell whether there is any txn context available. you have to trust container on that

for BMT bean (session only), one can use ut.getStatus() to find out the txn status. note that, BMT bean does not allow txn to propogate in i.e. the client can not pass it's txn to BMT bean.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A further thought. For a CMT bean, when you are in the middle of a method, you will always know the following (based upon its transaction attribute).

Called with an existing transaction context
===========================================
Mandatory

Possibly called with an existing transaction context
====================================================
Required, Supported

The other attributes (RequiresNew, NotSupported and Never) will never run in an existing transaction context.
 
Shiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic