我有一个用@Transactional注释的方法,该方法内部为同一类调用多个内部方法,这些内部方法可能会或可能不会调用任何其他外部服务方法。当它调用外部服务类方法时,它正在为一种表示回滚的方法工作,但是当调用同一类的另一个方法[仅外部服务类]时,同一服务却没有回滚,任何人都可以在这里帮助我。
@Transactional
public void processpayments(PaymentRequest request) {
request.getDetails.forEach(payment -> {
method1(payment);
});
// when doSomething1() is success,then its calling below method,externalService.doSomething2();// when it api fails,it is rollbacking properly,the process of calling is exactly same. Howcome this is rollbacking not dosomething1() is not rollbacking ?
}
private void method1(PaymentDetails details){
details.getDetails.forEach(detailedPayment -> {
method1_1(detailedPayment);
});
task3();
}
private void method1_1(DetailedPayment detailedPayment){
roundPayment();
task1();
task2();
}
private void roundPayment(){
}
private SomeObject task1(SomeObjet object){
// update object with if conditions
repository.save(object);
}
private SomeObject task2(){
// update object with if conditions
repository.save(object);
}
private SomeObject task3(){
// repository.save(updateSomeObject(someObject));
// externalService.doSomething1(double val1,double val2); // this is another service,which also uses another service,which uses restTemplate to call external service.,if http status is other than 200,i am throwing ExternalAPICall Exception,which should roll back full transaction starting from processpayments method
// its not roll backing
}
private void updateSomeObject(SomeObject object){
// update object based on few if conditions
}
有人可以在这里帮助我吗?我也想了解更多有关正确使用事务的信息,例如同一个类的多个内部方法,或由代理类调用的另一个类的多个内部方法,等等。