【发布时间】:2013-08-09 06:21:49
【问题描述】:
我有以下动作:
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
}
}
运行时,有时会报如下错误:
Message
Executing action [index] of controller [test.TestController] caused exception: Runtime error executing action
Caused by
Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [test.User#1]
为什么会发生这个错误?我认为withNewTransaction 会阻止这个错误。
【问题讨论】:
-
我是 Grails 的新手,你能解释一下这个答案吗?
标签: spring hibernate grails transactions grails-2.0