A and B access a set of data on the same page at the same time. A has modified one of the data. B's page has not been refreshed, so the information B sees is before A's modification. At this time, B also needs to modify this piece of data. How can I remind B that this piece of data has been modified.
I saw a way to find this data based on the last modified time before modifying the data (select * from xxx where updatetime = xxx and id= xxx). If it cannot be found, it means it has been modified. Check The description has not been modified when it arrives.
I would like to ask if there is a better way?
typecho2017-07-07 10:37:07
I remember that optimistic locking in hibernate is implemented using the version number field. After each update is successful, the value of the version number field is incremented by 1.
Before updating, first check whether the version number in the database and the version number saved in the page are the same. , if the version number becomes larger, the user is prompted that other users have modified the data during editing.
Of course, you can also use pessimistic locking. When entering the page, use select... for update to lock the record. At this time, other users cannot edit the locked record at the same time.
伊谢尔伦2017-07-07 10:37:07
I will do this - add a field, edit_num, +1 for each change, and compare it when B needs to be changed.
给我你的怀抱2017-07-07 10:37:07
Optimistic locking mechanism is implemented by adding a version field to the data
大家讲道理2017-07-07 10:37:07
Add a field to the data tableupdate_at
The type is TIMESATMP
, the default value is CURRENT_TIMESTAMP
, no other changes are needed
Whenever the data is updated, the value will be updated automatically
女神的闺蜜爱上我2017-07-07 10:37:07
Add a version field to this data. The version number starts from 0 by default. It will increment automatically if it is not modified. Just verify whether this version is consistent with the version in the database each time it is submitted.