我试图在我的 BootStrap.groovy 文件中创建一个用户域对象,但收到以下错误:
[ERROR]:AssertionFailure an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
域对象如下所示:从 afterInsert 方法中调用服务时会出现问题。该服务是非空的,并且在其上调用任何方法,包括 toString() 或 inspect(),似乎都会导致错误。
BootStrap.groovy
def newUser = new User(...)
newUser.save(flush:true, failOnError: true)
用户.groovy
class User extends Auth {
transient def userService
...
def afterInsert() {
log.debug "SERVICE: ${userService == null ? 'NULL': 'NOT NULL'}" // Gives: SERVICE: NOT NULL
// Either of the following lines cause the error when uncommented
//log.debug "SERVICE: ${userService.toString()}"
//userService?.makeUser(this)
}
}
这应该可以使用 BootStrap 还是我有一些根本性的错误?
或者,从 BootStrap 调用时是否可以忽略此代码?例如,类似于:
def afterInsert() {
if (notBootStrap()) {
...
}
}
任何输入将不胜感激!