I have two services as given below, and both has public methods with @Transactional annotation which is invoked via a self call.
@Service
public class ShopManager {
@Autowired
ShopRepository shopRepository;
public void createShop(List<Shop> shops){
// validation logic
// other business logic
createAllShops(shops);
}
@Transactional
public void createAllShops(List<Shop> shops){
shopRepository.saveAll(shops);
}
}
And here is the second service.
@Service
public class ItemManager {
@Autowired
ItemRepository itemRepository;
public void createItem(List<Item> items){
// validation logic
// other business logic
createAllItems(items);
}
@Transactional
public void createAllItems(List<Item> items){
itemRepository.saveAll(items);
}
}
As per the documentation Spring would ignore @Transactional annotation on self calls (implicit or explicit) since it uses proxies. However, in one service, the transaction management is working as expected and in the second service @Transactional is ignored.
Any idea why?