How to assign unique number to entity. The unique numbers range will be defined by user e.g. 1000000001 so the next number will be 1000000002, and so on.
Currently I'm maintaining a separate entity for managing the number range for my other entities.
What I'm doing right now while saving any entity. I read my number range entity and pick last number updated there and increment that number by 1 and assigned that number to my entity which to be saved. After that I'm saving my number range entity with updated number.
Problem: As it is a web application it is accessed by multiple users simultaneously. If multiple user save same entity at same time then same unique number is assigned to multiple records. How to overcome this issue?