Optimistic locking in JPA Hibernate with a best simple way

Step 1: Remember this annotation

 @Version
 @Column(name="OPTLOCK")
  private long version;

Think of it, add it to the Model @Entity or @Table which you want to apply

 @Entity
public class Employee{
  private @Id
  @GeneratedValue
  Long id;
  private String name;
  private String dept;
  private int salary;
  @Version
  private long version;
    .............
}

So everything is done

Step 2: Get detail in  plenty of optimistic locking


https://www.logicbig.com/tutorials/spring-framework/spring-data/optimistic-lock.html

https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/chapters/locking/Locking.html

http://docs.jboss.org/hibernate/orm/6.0/userguide/html_single/Hibernate_User_Guide.html#locking-optimistic


Comments

Popular posts from this blog

Fixing the DeepSpeed Import Error While Fine-Tuning the Qwen Model

Amazon Linux 2023 - User data configuration for launch templates to connect to the EKS cluster

How to create ISM policy and rotate logs in opensearch