I have enabled the sql logs in a SpringBoot application and I see that even I gave an order to the way I would like the updates to be executed, the logs shows that updates are being done in other order, I have 2 tables and the method that is updating those 2 tables is annotated with @Transactional.
I am wondering about this because when I update one of those tables the other one should also be consistent with this update, so I wanted to first update the one that needs to be consistent, but I think in my case there is no problem because at the end when the method returns succesfully the "commit" will be executed and the order wont matter because it is like an snapshot being saved in the database right?
for example:
Suppose we have 2 tables, "configuration" and "versioning".
Inside @Transactional method I do as follows:
@Transactional
public void update(){
configurationsRepository.saveAll(configurations);
versioningRepository.saveAll(versioning);
}
I need the configurations to be saved first because versioning is the one who knows which configurations are "productive", but when I see the sql logs I see that the versionings are being save/updated first which is "bad" because maybe it could point to non existant configurations.
So what would be a bad scenario is that versioning gets called and in those milliseconds of difference configurations is not updated... So far this has not happened, but I wonder if it can happen or my assumption about the commit at the end of the transaction is right, both will be updated at the same instant? And I believe that is the purpose of this Transactional hehe that everything gets saved or nothing gets saved at some instant