before write a record in db i have to do this task:
1- Read a max value of a field from a table
2- use this value to create new record
3- save the record
The value in step 1 must be unique.
The problem is that this task can be done by different client.
What is the best way to make this kind of operations atomic?
Thanks to all.
My suggestion:
– Add Unique constraint to the table’s field
– select max value using Hibernate, assign the value to the entity and save it.