我将数据库反向工程为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
    }
}

最佳答案

您必须修改TblAccessRight中的映射以指定tbl_fiscal_year_id指的是哪一列(在本例中为tblFiscalYear):

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

关于hibernate - 缺少列ID,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29854250/

10-12 06:24