【发布时间】:2012-08-21 22:54:34
【问题描述】:
我正在尝试在我的用户域类中使用 beforeInsert。
class User {
String reEnterPassword
static constraints = {
password(blank: false, nullable: false, size:5..50, validator: {password, obj ->
def reEnterPassword = obj.properties['reEnterPassword']
if(reEnterPassword == null) return true
reEnterPassword == password ? true : ['invalid.matchingpasswords']
})
reEnterPassword(bindable:true, blank: false);
}
def beforeInsert = {
password = password.encodeAsSHA()
}
String toString(){
name
}
static transients = ['reEnterPassword']
}
在我的控制器中我有保存方法(生成)
def save() {
def userInstance = new User(params)
if (!`userInstance.save(flush: true)`) {
render(view: "create", model: [userInstance: userInstance])
return
}
这是抛出异常 Grails运行时异常,org.hibernate.AssertionFailure: null id in entry(异常发生后不刷新Session),当域对象save方法遇到SQL异常时
我在auto timestamping 的文档中读到了 不要尝试在事件中刷新会话(例如使用 obj.save(flush:true))。由于在刷新期间触发了事件,这将导致 StackOverflowError。
在这种情况下如何保存我的userInstance.save(flush: true) 我试图删除flush:true 但我仍然遇到同样的错误。如果我删除flus:true..那么当我需要打电话时。当休眠将刷新所有这些记录。
我尝试了this JIRA ticket定义的解决方案 请帮帮我。谢谢
【问题讨论】:
-
回答问题所需的任何内容。请帮帮我。谢谢
标签: grails-domain-class grails-2.0