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
Post a Comment