Atomikos Forum

Independent nested UserTransaction

Hi!
I have two UserTransaction - outer and inner. If I rollback outer, inner transaction rollbacks too by default. How I can to create new independent inner UserTransaction?

UserTransaction ut1 = new UserTransactionImp();
ut1.begin();
// some work 1

UserTransaction ut2 = new UserTransactionImp();
ut2.begin();
// some work 2  - I want to save this work!
ut2.commit();

ut1.rollback();
Vasily Vasilkov Send private email
Wednesday, December 16, 2009
 
 
P.S.  My environment: Hibernate + Guice + Jetty.
Vasily Vasilkov Send private email
Wednesday, December 16, 2009
 
 
Hi,

Try using the UserTransactionManagerImp instead, and call suspend() right before starting the second transaction, like this:

TransactionManager utm = new UserTransactionManagerImp();
utm.begin();
...

Transaction t1 = utm.suspend();
//start new tx - you can reuse the same utm instance or another
utm.begin();
...
utm.commit();

utm.resume ( t1 );
...
utm.rollback();

HTH
Guy Pardon Send private email
Wednesday, December 16, 2009
 
 
It works, thank you!
Vasily Vasilkov Send private email
Wednesday, December 16, 2009
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics