缺少列ID

时间:2015-04-24 17:50:51

标签: hibernate grails gorm

我将数据库反向设计为Domain类。当我尝试运行应用程序时,出现错误

  

tbl_fiscal_year_id中缺少专栏 tblAccessRight

Domain类的定义和映射如下

class TblAccessRight {    
    long  rightID
    Character code
    String name
    Boolean active
    TblFiscalYear tblFiscalYear

    static hasMany = [tblPrivileges: TblPrivilege,
                      tblResourceTypes: TblResourceType]

    static mapping = {
        id column: "RightID", generator: "assigned",name:'rightID'
        version false
        table 'tblAccessRight'
    }

    static constraints = {
        code maxSize: 1
        name nullable: true, maxSize: 64
    }
}

class TblFiscalYear {
    String fiscalYear
    String title
    Boolean active
    Character defaultFy

    static hasMany = [tblAccessRights: TblAccessRight,
                      tblAppropriationGroups: TblAppropriationGroup,
                      tblBudgetProjectNames: TblBudgetProjectName,
                      tblC3ipocs: TblC3ipoc,
                      tblCises: TblCis,
                      tblCommentses: TblComments,
                      tblContractors: TblContractor,
                      tblCotrs: TblCotr,
                      tblDasds: TblDasd,
                      tblDirectors: TblDirector,
                      tblKeys: TblKey,
                      tblMiprpocs: TblMiprpoc,
                      tblObjectiveses: TblObjectives,
                      tblOp32s: TblOp32,
                      tblOrcs: TblOrc,
                      tblPeprojects: TblPeproject,
                      tblProgramElements: TblProgramElement,
                      tblPrograms: TblProgram,
                      tblResourceTypes: TblResourceType,
                      tblResources: TblResource,
                      tblRoles: TblRole,
                      tblTrackChangeses: TblTrackChanges,
                      tblTransactionses: TblTransactions]

    static mapping = {
        id name: "fiscalYear", generator: "assigned" ,type:'string', column:'FiscalYear'
        version false

        table 'tblFiscalYear'
    }

    static constraints = {
        fiscalYear maxSize: 4
        title nullable: true, maxSize: 48
        defaultFy nullable: true, maxSize: 1
    }
}

1 个答案:

答案 0 :(得分:1)

您必须修改TblAccessRight中的映射,以指定哪个列(本例中为tbl_fiscal_year_idtblFiscalYear指的是:

static mapping = {
    table 'tblAccessRight'
    id column: "RightID", generator: "assigned",name:'rightID'
    tblFiscalYear column: 'tbl_fiscal_year_id'
    version false
}