For troubleshooting mybatis concurrency, refer to hibernate and mybatishibernate.
A typical example is that two bank operators operate on the same account at the same time. For example, IF operator A and operator B read an account with A balance of 1000 yuan at the same time, operator A adds 100 yuan to the account, and operator B deducts 50 yuan from the account at the same time. Operator A submits the account first, submit after B. The actual account balance is 1000-50 = 950 yuan, but it should be 1000 + 100-50 = 1050. This is a typical concurrency issue.
A simple solution: Add 1 to the version number field during the UPDATE process, and then UPDATE returns the number of rows in the UPDATE result, which is determined by the number of rows.
Update account set price = # price #, version = version + 1
Where id = # id # and version = # vsersion #
If the number returned by the update execution is 0, it indicates that a concurrent modification is generated. You need to obtain the latest data and then perform the update operation.
An ORM framework or implementation, such as Hibernate and JPA, uses the version number to determine the value returned after UPDATE. If the value is less than 1, an optimistic lock exception is thrown for concurrent modification.