Grails旧映射错误列与外键中引用列的数据类型不同

时间:2014-11-06 05:46:56

标签: hibernate grails gorm hibernate-mapping grails-2.0

我正在使用grails创建一个解决方案,该解决方案将在已存在其他表的同一数据库模式中创建表。我使用db reverse enginneer插件为我现有的遗留表创建一个域。

但是,当我创建具有属于反向工程师表的属性的新域类并运行应用程序以将模型发布到数据库时,我收到以下错误:

Unsuccessful: alter table WITHDRAW add constraint FK2B28E9D63EA7A90E foreign key (PERSON_id) references PERSON
Error |
2014-11-06 00:20:03,010 [localhost-startStop-1] ERROR hbm2ddl.SchemaUpdate  - Column 'PERSON.personID' is not the same data type as referencing column 'WITHDRAW.PERSON_id' in foreign key 'FK2B28E9D63EA7A90E'.

以下是经过逆向设计的遗留表

package ic

import org.apache.commons.lang.builder.ToStringBuilder

class Person {

String studentNumber
String stateId
String staffNumber
String staffStateId
Integer modifiedById

static mapping = {

    version false

    id column: "personID", generator: "assigned"
    studentNumber column: "studentNumber"
    staffNumber column: "staffNumber"
    stateId column: "stateId"
    staffStateId column: "staffStateId"
    modifiedById column: "modifiedById"


}

static constraints = {

    stateId nullable: true, maxSize: 15
    studentNumber nullable: true, maxSize: 15
    staffNumber nullable: true, maxSize: 15
    staffStateId nullable: true, maxSize: 20
}


@Override
public String toString() {
    return new ToStringBuilder(this)
            .append("id", id)
            .append("studentNumber", studentNumber)
            .append("stateId", stateId)
            .append("staffNumber", staffNumber)
            .append("staffStateId", staffStateId)
            .append("modifiedById", modifiedById)
            .toString();
    }
}

以下是创建但上面提到的错误的新表(不是遗留的)

package iccustom

class Withdraw {

    Person person
    WithdrawType withdrawType
    Date withdrawDate
    Date dateCreated
    Date lastUpdated

    static belongsTo = [person:Person]

    static mapping = {
        //probably I need to something here but not sure of the correct syntax
    }

    static constraints = {
        person nullable:false, blank:false
        withdrawType nullable:false, blank:false
        withdrawDate nullable:false, blank:false 
    }

}

表创建得很好,但我真的想要创建外键。我希望Withdraw上的FK引用Person Table

中的personId列

我尝试过放置@ManyToOne和@JoinColumn(名字=" personId),但这也不起作用。

任何帮助都会有很大的帮助。

0 个答案:

没有答案