[英]GORM: null check on new property leads to QueryException
I've added a new property uuid
into the GORM mapping of the formerly existing domain class BComponent: 我在以前存在的域类BComponent的GORM映射中添加了新属性
uuid
:
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
}
When it comes to executing code dealing this new property in BootStrap.groovy, like... 在执行代码处理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()
}
}
}
... the following Exception is thrown: ...引发以下异常:
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)
...
Why is that? 这是为什么? Is my null check incorrect?
我的null检查不正确吗? I've adopted it from similar checks that work fine, like there is:
我从类似工作的类似检查中采用了它,例如:
BComponent.executeQuery("select bc.id from BComponent as bc where bc.normname is null and bc.name is not null") // ...
Did I forget something? 我忘记了什么吗? I've already executed
我已经执行了
$ grails clean
What else? 还有什么? Thx!
谢谢!
I forgot to add uuid as a property in my Groovy class code. 我忘记在我的Groovy类代码中添加uuid作为属性。 So:
所以:
class BComponent{
// ...
String uuid
// ...
}
has solved the problem. 解决了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.