You will only be able to do this if you use bean managed transactions.

In your session bean, here's some starter methods that you can use to start and end 
your transactions:

        protected int beginTransactionIfRequired(int timeoutInSeconds) {
  |             UserTransaction tran = this.sessionContext.getUserTransaction();
  |             int initialTranStatus;
  |             try {
  |                     initialTranStatus = tran.getStatus();
  |                     switch (initialTranStatus) {
  |                             case Status.STATUS_ACTIVE:
  |                                     // we are ok just using the current 
transaction.
  |                                     break;
  |                             case Status.STATUS_NO_TRANSACTION:
  |                                     // create a new transaction.
  |                                     try {
  |                                             
this.sessionContext.getUserTransaction().setTransactionTimeout(timeoutInSeconds); 
  |                                             tran.begin();
  |                                     } catch (NotSupportedException e) {
  |                                             throw new EJBException("Unable to 
start transaction: " + e.getMessage());
  |                                     }
  |                                     break;
  |                             default:
  |                                     throw new EJBException("Transaction status 
invalid, status is: " + initialTranStatus);
  |                     }
  |             } catch (SystemException e) {
  |                     throw new EJBException("Unable to begin transaction",e);
  |             }
  |             return initialTranStatus;
  |     }
  | 
  |     protected void completeTransactionIfRequired(int initialTransactionStatus) {
  |             UserTransaction tran = this.sessionContext.getUserTransaction();
  |             
  |             if (initialTransactionStatus == Status.STATUS_NO_TRANSACTION) {
  |                     try {
  |                             if (tran.getStatus() == Status.STATUS_MARKED_ROLLBACK) 
{
  |                                     tran.rollback();
  |                             } else {
  |                                     tran.commit();
  |                             }
  |                     } catch(Exception e) {
  |                             throw new EJBException("Unable to complete 
transaction",e);
  |                     }
  |             }
  |     }
  | 
  | 

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3844576#3844576

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3844576


-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to