cancel
Showing results for 
Search instead for 
Did you mean: 

problem with transaction in Session Bean (Container Transactions)

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

hi,

how start new transaction for eveery iteration in BusinessMethod.

regards

Guru

former_member182372
Active Contributor
0 Kudos

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