两次 Grails GORM 绑定字段
Grails GORM binding field twice
我有一个简单的域对象。
class Product {
public static final String TRACE_SKU="236"
Integer xRefId
static constraints = {
xRefId(nullable:true)
}
static mapping = {
table 'product'
version false
id generator:'identity', column:'id'
xRefId column:'xref_id'
cache usage: 'nonstrict-read-write'
}
}
我在应用程序启动时以及 运行 测试用例时收到以下错误。
Repeated column in mapping for entity: com.appdroplet.tricor.common.domain.product.Product column: xref_id (should be mapped with insert="false" update="false")
此外,当我检查错误日志时,我看到了这条消息。
[ 15.11.16 09:34:50.403] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Mapping Grails domain class: com.appdroplet.tricor.common.domain.product.Product -> product
[ 15.11.16 09:34:50.403] [main] [DEBUG] [org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory] Returning cached instance of singleton bean 'orgGrailsBeansConstraintsEvaluator'
[ 15.11.16 09:34:50.405] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] bound property [id] to column name [id] in table [product]
[ 15.11.16 09:34:50.405] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding persistent property [XRefId]
[ 15.11.16 09:34:50.405] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding property [XRefId] as SimpleValue
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] bound property [XRefId] to column name [xref_id] in table [product]
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding persistent property [xRefId]
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding property [xRefId] as SimpleValue
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] bound property [xRefId] to column name [xref_id] in table [product]
出于某种原因,Grails 绑定了相同的 属性 两次。
项目正在使用 Grails 2.3.0
您不能让 属性 以 Id 结尾。
有以下class
Book {
Author author
}
book.authorId
按照 grails 惯例意味着你想获得 属性 作者的 Id。像您一样使用其他方法可能会产生错误。
书 table 中的作者默认映射为 author_id。
您可以在 documentation
中了解有关 GORM 的更多信息
我有一个简单的域对象。
class Product {
public static final String TRACE_SKU="236"
Integer xRefId
static constraints = {
xRefId(nullable:true)
}
static mapping = {
table 'product'
version false
id generator:'identity', column:'id'
xRefId column:'xref_id'
cache usage: 'nonstrict-read-write'
}
}
我在应用程序启动时以及 运行 测试用例时收到以下错误。
Repeated column in mapping for entity: com.appdroplet.tricor.common.domain.product.Product column: xref_id (should be mapped with insert="false" update="false")
此外,当我检查错误日志时,我看到了这条消息。
[ 15.11.16 09:34:50.403] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Mapping Grails domain class: com.appdroplet.tricor.common.domain.product.Product -> product
[ 15.11.16 09:34:50.403] [main] [DEBUG] [org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory] Returning cached instance of singleton bean 'orgGrailsBeansConstraintsEvaluator'
[ 15.11.16 09:34:50.405] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] bound property [id] to column name [id] in table [product]
[ 15.11.16 09:34:50.405] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding persistent property [XRefId]
[ 15.11.16 09:34:50.405] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding property [XRefId] as SimpleValue
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] bound property [XRefId] to column name [xref_id] in table [product]
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding persistent property [xRefId]
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] Binding property [xRefId] as SimpleValue
[ 15.11.16 09:34:50.407] [main] [DEBUG] [org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder] [GrailsDomainBinder] bound property [xRefId] to column name [xref_id] in table [product]
出于某种原因,Grails 绑定了相同的 属性 两次。
项目正在使用 Grails 2.3.0
您不能让 属性 以 Id 结尾。
有以下class
Book {
Author author
}
book.authorId
按照 grails 惯例意味着你想获得 属性 作者的 Id。像您一样使用其他方法可能会产生错误。
书 table 中的作者默认映射为 author_id。
您可以在 documentation
中了解有关 GORM 的更多信息