How to assign a unique entity number. The range of unique numbers will be determined by the user, for example. 1000000001, so the next number will be 1000000002, etc.
I currently maintain a separate object to control the range of numbers for my other objects.
What I'm doing right now, while saving any object. I read my range number and remembered the last number updated there, and increased that number by 1 and assigned this number to my object, which will be saved. After that I save my range number with the updated number.
Problem: Since this is a web application, several users are accessing it simultaneously. If several users save the same object at the same time, then the same unique number is assigned to several records. How to overcome this problem?
Any comments would be greatly appreciated. Thanks in advance.
source
share