【发布时间】:2015-03-12 09:04:57
【问题描述】:
我有一个域类 DbUserSchemaServer 具有瞬态属性 unassign
class DbUserSchemaServer {
static transients = ["unassign"]
DbUser user
String schema
DbServer server
BigInteger objects
Date creationDate
String schemaStatus //for dropping
Boolean protect
//Transients
Boolean unassign
static constraints = {
user unique:false, nullable: false, blank:false
schema unique:'server', nullable: false, blank:false
server unique: false, nullable: false, blank:false
objects blank:false, nullable:false
creationDate blank:false, nullable:false
schemaStatus nullable:true, blank: false
}
static mapping = {
protect defaultValue: false
unassign defaultValue: false
}
}
在服务中,我尝试更改 DbUserSchemaServer 实例的 protect 属性的值。方法如下
public Boolean protectSchema(DbUserSchemaServer usrSchSrvInst) {
println "protectSchema: "+usrSchSrvInst.schema
if(!usrSchSrvInst.protect) { // If unprotected
if(usrSchSrvInst.schemaStatus.equals("drop")) // If schema status is drop
usrSchSrvInst.setSchemaStatus(null)
usrSchSrvInst.setProtect(true)
println "-->"+usrSchSrvInst.getProtect()
return true
}
else { // If already protected
return true
}
return false
}
当我尝试通过 setProtect(true) 调用更改模式 TEST_SCHEMA_1 的状态时,它在本地视图中发生了变化(在 std println 上打印为 true),但在数据库条目。我试图通过instance.save() 保存实例,但行为没有改变。
我现在使用 grails 2.4.4。以前,我使用的是 2.2.4 版本,它按预期工作。当我将应用程序迁移到版本 2.4.4 时,我遇到了这个问题。可能是什么原因,如何解决。
【问题讨论】:
标签: grails grails-2.0 grails-domain-class