on 09-01-2006 8:15 AM
hi,
In my session bean i am calling 4 methods within the <b>for</b> loop .
example:
Session Bean{
businessmethod()
for(int i=0;i<10;i++){
method1();
method2();
method3();
}
}
in the above example method1,method2,method3 are belongs to different session bean .these methods are containing transaction attribute as <b>required</b>.
my problem is :
in iteration 1 of for loop all method are executed successfully, and 2nd iteration also. in 3rd iteration Exception occured in method3.
<u><i><b>i do't want to rollback method callings in 1st,2nd iteration</b></i></u>.
if it is possible pls guide me to do this
regards
Guru
Hi,
your businessmethod() should start a new transaction and method1(), method2(), method3() should set to use the transaction created for businessmethod(). If an exception occured in one of the method calls you can rollback the whole transaction.
Regards
Sebastian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Guru,
Mark your session bean`s transactions type as "Bean" (<transaction-type>Bean</transaction-type>). Use following code:
public void setSessionContext(SessionContext context) {
myContext = context;
}
private SessionContext myContext;
public void businessmethod() {
for(int i=0;i<10;i++){
try {
myContext.getUserTransaction().begin();
method1();
method2();
method3();
myContext.getUserTransaction().commit();
} catch (final Exception e) {
//report and log
try {
myContext.getUserTransaction().rollback();
} catch (final Exception ex) {
//report and log
}
}
}
}
Best regards, Maksim Rashchynski
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.