1

I have a Spring JPA multi threaded program in which multiple threads are saving to one of the tables. I wanted to know what will happen in the following scenario:

2 threads pick up same object to process and save to the table. Data is successfully saved. A contention resolution mechanism identifies that one of the data is a duplicate and makes a delete request. Will this delete also remove the object from the context of the first thread ?

(We have an intermittent issue appearing when an object which is supposed to be a successful return via the save method of JPA is suddenly logged as null.)

1 Answers1

0

To avoid this you can try to use saveAndFlush instead of save. This might solve your problem of unexpected deletion.

Refer: Difference between save and saveAndFlush in Spring data jpa