I have read the official documentation of Spring about the
@Transactional(Propagation.REQUIRED)
annotation but still have some doubts. I will show you an example about how I thinks it behaves:
First Service
public class MyServiceImpl implements MyService{
@AutoWired
private OtherService otherService;
@Transactional(Propagation.REQUIRED)
public void saveItem(Item item){.....}
@Transactional(Propagation.REQUIRED)
public void updateItem(Item item){....}
}
@Transactional(Propagation.REQUIRED)
public void deleteItem(Item item){
otherService.checkItem(item);
...........
}
}
Second Service
public class OtherServiceImpl implements OtherService {
@Transactional(Propagation.REQUIRED)
public void checkItem(Item item){.....}
}
Making calls to MyServiceImpl class from a Spring Controller:
If I make one call to
saveItem()
, a new physical and logical transaction will be created, right?If I make two calls to this service from the controller, one to
saveItem()
and the next toupdateItem()
,Spring will create for each method two physical different transactions, right?If I make a call to
deleteItem()
, only one physical transaction will be created because it will be opened a transaction when deleteItem is called but the inner call from this method tootherService.checkItem()
will reuse the first physical transaction, right?