如何解决Grails错误重复实体映射中的列?在现有的Postgresql数据库上

时间:2010-12-16 05:31:51

标签: grails grails-domain-class

我在Grails中有以下域名

class Customer {
    static mapping = {
         table 'customer'
         // version is set to false, because this isn't available by default for legacy databases
         version false
         id column:'customerid' //generator:'identity', 
    }
    Long customerid
    Long customergroupid
    String username
    String password
    String name
    String street
    String city
    String province
    String postcode
    String country
    Date dateregistered
    String balance
    Long parentid
    String parentrebate
    String metapath
    Long metalevel
    Integer smsreplystatus
    Integer status
    String reversalurl

    static constraints = {
        customerid(insert:false,update:false)
        customergroupid(max: 9999999999L)
        username(size: 1..20, blank: false)
        password(size: 1..32, blank: false)
        name(size: 1..20, blank: false)
        street(size: 0..50)
        city(size: 0..20)
        province(size: 0..20)
        postcode(size: 0..5)
        country(size: 0..20)
        dateregistered(nullable: true)
        balance()
        parentid(max: 9999999999L)
        parentrebate()
        metapath(size: 1..255, blank: false)
        metalevel(max: 9999999999L)
        smsreplystatus(max: 99999)
        status(max: 99999)
        reversalurl(size: 0..50)
    }
    String toString() {
        return "${customerid}" 
    }
}

我有现有数据库和现有数据,并且已经使用GRAG映射到GORM但我收到此错误

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: postgresql.Customer column: customerid (should be mapped with insert="false" update="false")
    ... 23 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: postgresql.Customer column: customerid (should be mapped with insert="false" update="false")

1 个答案:

答案 0 :(得分:1)

有同样的问题,请删除“Long customerid”

这可能不是一个可行的解决方案,但至少应用程序会编译并创建表格。

根本没有调查,因为我设法让这个工作 - 也许在设置自定义标识列时,隐含了属性定义(因此“重复列...”错误)