'Is insert into in sql synchronised or Async?

We have been developing 2 endpoints in spring boot that one of them stores itemA in a Postgres tableA and the other end point stores itemB in tableB based on the existence of itemA(TableA has one to many relation with tableB). In our preference test, we call the endpointA to create itemA and then if we get status ok from the endpointA, we add the itemA id to an array-list and we randomly pick one id from the list and use it for calling endpointB and creating itemB. In some cases we get race condition, in which we want to persist itemB in tableB but we get exception that itemA is not in the table. In our logs we see for example:

itemA has been landed to our serviceA to be stored in the tableA at 12:00:000

if we check the database later we see that ItemA is in the database created at 12:00:008

itemB has been landed to our serviceB to be stored in the tableB at 12:00:005

and

then exception: the itemA does not exist!

For storing in the tables we use sql command like: "insert into tableA ..."

How it's possible that we get status ok from endpointA meaning that itemA is stored but still not in the table. Is "insert into" an async process? or does this have anything todo with spring boot @Transactional? any help would be appreciated!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source