我正在使用 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)
})
}
}
发送电子邮件后,它给出了一个错误。