Spirng transaction (optimistic lock) problem?

executing the following sql, in a while loop will result in the non-execution indicated in the figure. Sql uses the version field to implement optimistic locks.

clipboard.png


@Transactional(rollbackFor = Exception.class)



you can check and modify the return value by yourself. If the number of rows affected is 0, you can throw an exception by yourself. Otherwise, how many row pairs are semantically correct to perform update modifications in the database.


returns 0 because the previous statement has changed version=0+1=1, and then executed under the old conditions, of course, no data can be returned 0, but this does not mean that

has not been executed.
Menu