@Transactional
public void save(String myIds)
{
synchronized (this)
{
List<mydata> data = getDataToSaveOrUpdate(myIds);//Returns the new dataList and updates old data
repository.saveAll(data);
logger.info("request processed");
}
logger.debug("exiting the method");
}
When this method is called in two separate request from postman what happens synchronized block gets completed but inserts are going and second request start reading from the data base .So second thread founds same data to insert in both the request and give unique key violation error how should we resolve this problem in springboot data jpa hibernate