0

I have a two instances of one spring boot microservice. If two requests are sent at the same time, and the second request can update the row that was created by the first request. How i can prevent this? For example the table contains this columns :id,format,username,groupName and if a row exists (3,"test","test","test") and if we try to insert another row with same groupName and format,the insertion should fail.

Thx.

Regards, Petar

1 Answer 1

1

You can use optimistic lock and avoid overriding of row.

public class A {

   @Id
   private String id;

   @Version
   private Long version;

}

@Version annotation will cover optimistic lock for you. For More detail : https://www.baeldung.com/jpa-optimistic-locking

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.