Hi,
I have a java application which calls a stored procedure to insert data into a table.Multiple threads of java call the same procedure at the same time. Sometimes it happens that few threads send the same data as parameter to the procedure. In that case i get the error : "Cannot insert duplicate key row in object ...."
The functionality of the proc is - It checks if a given data (Based on Unique key) is present in the table or not. If present it doesnt insert.It simply updates. If no row present, it will insert a new row.
So when both the concurrent processes search for the existence of data, both of them dont find the data. Both go on to insert the same data which gives the problem.
I tried using WITH(HOLDLOCK) and WITH(NOLOCK), but still get the same error.
Can anyone please help in this.
Regards,
Subrat