If my session bean with single method insert record into 2 entity beans, how can know that the process is done in same transaction (the attributes for these beans are Required)?

Jesper Lai Petersen

If yor method in the session bean is already running under a transaction the calls to any other bean which have been deployed with trans-attribute 'Required' will be executed within the same transaction context.

So if your session bean is using container-managed transactions and your method is deployed with 'Required', 'RequiresNew' or 'Mandatory', you can safely assume that the calls to your entity beans are handled under same transaction. If you're not running in a transaction, a separate transaction will be set up for each call to your entity beans.

If your session bean is using bean-managed transactions, you can ensure that the calls are handled in the same transaction by :

javax.transaction.UserTransaction tran= null;
try{
  tran=ctx.getUserTransaction();
  tran.begin();
  myBeanHome1.create(....);
  myBeanHome2.create(...);
  tran.commit();
}catch(...){}
You may want to check if you're already running in a transaction by calling tran.getStatus().
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact