【发布时间】:2013-06-06 20:41:05
【问题描述】:
我正在使用 grails,并且我有 Web 应用程序。在其中调用更新用户配置文件时,我为其提供服务,在其中我通过请求参数设置当前用户属性
user.properties = params (params-request parameters),
在我的用户域类中,我有onChange 方法(审计插件)。
因此,当控件转到用户域onChange 方法时,在将属性设置为用户配置文件后调用此方法时会出错
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.web.User#3].
我仍在寻找如何更新行的解决方案。 提前致谢。
//userController update method -
def user = User.get(params.id)
user.properties = params
user.save(flush:true)
//and in user domain onChange method-
def onChange = { oldMap,newMap ->
try{
Msg.append("Your profile has been updated successfully with the following changes: ");
oldMap.each({ key, oldVal ->
if(oldVal != newMap[key]) {
if(key =="firstName" || key =="gender" || key =="lastName" || key =="phoneNo" || key =="city"){
Msg.append(" * $key changed from $oldVal to " + newMap[key])
}
}
sendMail(Msg,newMap.email)
})
}
}
发送邮件后报错。
【问题讨论】:
-
我猜你在用户域中也有
static auditable = true? -
sendMail 的内容是什么?
-
您的项目环境是什么?生产或开发
-
我在用户域中设置了 static auditable = true 并且项目环境正在开发中。
标签: grails