2016-11-15 60 views
0

我有一个简单的域对象。Grails 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

+0

如果删除'xRefId柱发生了什么:“xref_id''? – injecteer

+0

它在映射上没有错误,但它似乎绑定了两个属性:表[product]中的'bound property [XRefId]到表名[xref_id]'和表[product中的绑定属性[xRefId]到列名[x_ref_id] ]' – mfleshman

+0

将字段重命名为“xrefId”是个问题吗? – injecteer

回答

0

您不能拥有以Id结尾的属性。

具有下列类

Book { 
    Author author 
} 

book.authorId由Grails的约定意味着你想要得到的财产作者的ID。如你所做的其他用途,可能会产生错误。

书本表中的作者默认映射为author_id。

你可以了解更多关于格姆在其documentation

+0

谢谢,这是记录在哪里? – mfleshman

+0

我已经添加了doc url,它更延伸,grails doc – quindimildev

+0

我不知道这是否写在那里,但我试图找到它;) – quindimildev