GORM:对新 属性 的空检查导致 QueryException
GORM: null check on new property leads to QueryException
我已将新的 属性 uuid
添加到以前存在的域 class BComponent:
的 GORM 映射中
static mapping = {
tablePerHierarchy false
id column:'bc_id'
uuid column:'bc_uuid', type:'text'
name column:'bc_name', type:'text', index:'bc_name_idx'
normname column:'bc_normname', type:'text', index:'bc_normname_idx'
version column:'bc_version'
// ... other properties
}
在 BootStrap.groovy 中执行处理此新 属性 的代码时,例如...
BComponent.withTransaction() {
BComponent.executeQuery("select bc.id from BComponent as bc where bc.uuid is null").each { bc_id ->
BComponent.withNewTransaction {
BComponent bc = BComponent.get(bc_id)
bc.generateUuid()
bc.save()
bc.discard()
}
}
}
...抛出以下异常:
ERROR context.GrailsContextLoaderListener - Error initializing the application: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]; nested exception is org.hibernate.QueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]; nested exception is org.hibernate.QueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:671)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:414)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:416)
at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:348)
...
这是为什么?我的空检查不正确吗?我从类似的检查中采用了它,效果很好,比如:
BComponent.executeQuery("select bc.id from BComponent as bc where bc.normname is null and bc.name is not null") // ...
我是不是忘记了什么?我已经执行了
$ grails clean
还有什么?谢谢!
我忘记在我的 Groovy class 代码中添加 uuid 作为 属性。所以:
class BComponent{
// ...
String uuid
// ...
}
已解决问题。
我已将新的 属性 uuid
添加到以前存在的域 class BComponent:
static mapping = {
tablePerHierarchy false
id column:'bc_id'
uuid column:'bc_uuid', type:'text'
name column:'bc_name', type:'text', index:'bc_name_idx'
normname column:'bc_normname', type:'text', index:'bc_normname_idx'
version column:'bc_version'
// ... other properties
}
在 BootStrap.groovy 中执行处理此新 属性 的代码时,例如...
BComponent.withTransaction() {
BComponent.executeQuery("select bc.id from BComponent as bc where bc.uuid is null").each { bc_id ->
BComponent.withNewTransaction {
BComponent bc = BComponent.get(bc_id)
bc.generateUuid()
bc.save()
bc.discard()
}
}
}
...抛出以下异常:
ERROR context.GrailsContextLoaderListener - Error initializing the application: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]; nested exception is org.hibernate.QueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]; nested exception is org.hibernate.QueryException: could not resolve property: uuid of: org.gokb.cred.BComponent [select bc.id from org.gokb.cred.BComponent as bc where bc.uuid is null]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:671)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:414)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:416)
at org.springframework.orm.hibernate3.HibernateTemplate.executeFind(HibernateTemplate.java:348)
...
这是为什么?我的空检查不正确吗?我从类似的检查中采用了它,效果很好,比如:
BComponent.executeQuery("select bc.id from BComponent as bc where bc.normname is null and bc.name is not null") // ...
我是不是忘记了什么?我已经执行了
$ grails clean
还有什么?谢谢!
我忘记在我的 Groovy class 代码中添加 uuid 作为 属性。所以:
class BComponent{
// ...
String uuid
// ...
}
已解决问题。