I have method which updates to Item quantity.
MyEntity has @Version annoted version property as long.
There is an item list endpoint /items
Also there is an item update endpoint /item/update
(consider as product stock, buying an item)
So N concurrent users want's to update same item.
But there throws org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
that exception. While updating.
And also at this time, /items
endpoint couldn't return data. Or waits user to return with too much latency.(If updating users count too much at this time it also gets an exception timeout
).
So How can I handle that situation without any missing? (Can be good implementation )