I have a @Service
class which has a @Transactional
method that calls another @Transactional
method on the another service. Something like that:
@Service
public class AService {
@Autowired
BService b;
@Autowired
ARepository aRepo;
@Transactional
public void methodOne(){
try{
b.methodTwo();
}catch(RuntimeException e){}
aRepo.save(new A());
}
}
@Service
public class BService{
@Transactional
public void methodTwo(){
if(true)
throw new RuntimeException();
}
}
I expect that A entity will be insert, but if any nested transaction throw exception insert will reject even this exception was handled at AService.methodOne()
.
I can annotate methodTwo()
with @Transactional(propagation = Propagation.REQUIRES_NEW)
. But it will beat performance.
REQUIRES_NEW
. Yes that is a performance impact as it starts a new tx. – Rawalpindi