I have the following service layout of nested transactions:
@Component
public class Main implements RPCInterface {
@Autowired
private ServiceA serviceA;
@Autowired
private ServiceB serviceB;
@Autowired
private ServiceC serviceC;
@Override
@Transactional (value="txManager", propagation=Propagation.REQUIRED, rollbackFor={ExceptionOne.class, ExceptionTwo.class, ExceptionThree.class})
public void outerMethod() throws ExceptionO {
try {
serviceA.methodA();
serviceB.methodB();
serviceC.methodC();
} catch (ExceptionOne e) {
throw new ExceptionO(e.getMessage, e);
} catch (ExceptionTwo e) {
throw new ExceptionO(e.getMessage, e);
} catch (ExceptionThree e) {
throw new ExceptionO(e.getMessage, e);
}
}
}
@Service
public class ServiceA implements SA {
@Autowired
private ServiceA1 serviceA1;
@Override
public void methodA() {
serviceA1.methodA1();
}
}
@Service
public class ServiceA1 implements SA1 {
@Autowired
private ServiceDBTable1 serviceDBTable1;
@Autowired
private ServiceA1A serviceA1A;
@Transactional
@Override
public void methodA1() {
serviceDBTable4.callToMapper4();
serviceA1A.methodA1A();
}
}
@Service
@Transactional (value="txManager", propagation=Propagation.REQUIRED)
public class ServiceA1A implements SA1A {
@Autowired
private ServiceDBTable2 serviceDBTable2;
@Override
public void methodA1A() {
serviceDBTable1.callToMapper1();
}
}
@Service
public class ServiceB implements SB {
@Autowired
private ServiceDBTable3 serviceDBTable3;
@Override
@Transactional (value="txManager", propagation=Propagation.REQUIRED)
public void methodB() {
serviceDBTable3.callToMapper3();
}
}
@Service
public class ServiceC implements SC {
@Override
public void methodC() throws ExceptionThree {
// code that throws ExceptionThree
}
}
I need to make all the DB calls within ServiceA and ServiceB nested calls to rollback when ServiceC#methodC() throws an exception (or any of them for that matter that throws an exception -- ServiceA or ServiceB).
I tried to make Main#outerMethod transactional with REQUIRED propagation, but it seems like the database commits are not being rolled back. I have even specified the specific classes with rollbackFor but the commits persist. Does anyone know how to fix this issue?
innerMethodThreemust be called after 1) and 2). - NuCradle@TransactionalfromServiceA1.methodA1()andServiceB.methodB()and placed it onMain#outerMethod(), but the rollbacks are not occurring. - NuCradle