>1. If the single method call involves multiple transactions
> then instead of using multiple transactions in a single method call,
> it is better to break the method into multiple methods,
> with each of the multiple methods having its own container-managed
> transaction.
Use 2 session beans: bean A and bean B.
The client calls Bean A, which has transaction attribute "NOT_SUPPORTED", so that bean
A doesn't start a transaction. Then Bean A calls each of the three methods on bean B,
with those methods set with transaction attribute "REQUIRED". Since Bean A won't
start a transaction, each call to a method of bean B will start and commit their own
transactions.
//Psuedo code... (I'm leaving out the home.create steps for brevity)
public class BeanA implements javax.ejb.SessionBean {
//Use TX Attribute "NOT_SUPPORTED"
public void foo() {
beanB.method1();
beanB.method2();
beanB.method3();
}
}
public class BeanB implmenets javax.ejb.EntityBean {
//Use TX Attribute "REQUIRED" for each of these methods
public void method1() {...}
public void method2() {...}
public void method3() {...}
}
>2. You define a single transaction that "spans" multiple EJB method calls.
> For example, you define a stateful session EJB that uses one method to
> begin a transaction, and another method to commit or roll back a
>transaction
To have 1 transaction span both all 3 calls to bean B, simply change bean A's
transaction attribute to "REQUIRED". Now Bean A starts the transaction and each
method in Bean B will participate in Bean A's transaction.
//Psuedo code... (I'm leaving out the home.create steps for brevity)
public class BeanA implements javax.ejb.SessionBean {
//Use TX Attribute "REQUIRED" to have all of foo() be in 1 transaction
public void foo() {
beanB.method1();
beanB.method2();
beanB.method3();
}
}
public class BeanB implmenets javax.ejb.EntityBean {
//Use TX Attribute "REQUIRED" for each of these methods
public void method1() {...}
public void method2() {...}
public void method3() {...}
}
>How can we use the Bean Managed Transactions or the container managed
>transactions in above scenarios......
I hope the above helps. Container transactions are much easier to work with then bean
managed transactions. To learn more about managing transaction boundaries, you should
get a good EJB Book or opt for a good EJB training class.
Doug Bateman
Sr. Enterprise Java Architect and EJB Instructor
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".