spring - Error: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) -
i have following action:
def index() {    user.withnewtransaction {     def user = user.get(params.userid)    user.name = "test"    user.save(flush:true)     response.setcontenttype("image/gif")    response.outputstream << pixel_bytes_of_a_gif_image    return   } }   when running, following error:
message executing action [index] of controller [test.testcontroller] caused exception: runtime error executing action caused row updated or deleted transaction (or unsaved-value mapping incorrect): [test.user#1]   why error happen? thought withnewtransaction prevent error.
you can use pessimistic locking
use:
user user = user.lock(params.userid)   or
user user = user.findbyid(params.userid, [lock: true])          
Comments
Post a Comment