基于版本号
CREATE TABLE `test_optimistic_lock_version` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`version` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4
@Entity
@Table(name = "test_optimistic_lock_version")
public class TestOptimisticLockVersion {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
private String name;
//版本
@Version
private Integer version;
}
@Repository
public interface TestOptimisticLockVersionRepository extends JpaRepository<TestOptimisticLockVersion,Long> {
}