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

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

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

java - Cannot secure connection using TLS -