spring entity concurrency control while persisting into database -


i trying control concurrent access same object in spring+jpa configuration. example, have entity named a. multiple processes updating same object of a. using versioning field controlling here issue: example 2 processes reads same entity (a) having version=1. 1 process update entity , version gets incremented. when 2nd process tries persist object, optimistic lock exception thrown. using spring services , repository access objects. please me here?

what's problem then? that's how it's supposed work.

you can catch jpaoptimisticlockingfailureexception , decide there.

this, example, give validation error message on spring mvc form:

... if(!bindingresult.haserrors()) {   try {     foorepository.save(foo);   } catch (jpaoptimisticlockingfailureexception exp){       bindingresult.reject("", "this record modified user. try refreshing page.");     } } ... 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -