在joinTable(遗留数据库)中的多对多关系中,Grails为复合键自定义名称



grails/gorm似乎会忽略多对多关系中联接表上的列名,如果一个域类具有复合id,例如:

class Following implements Serializable {
    ...
    static hasMany = [operationTypes:OperationType]
    static belongsTo = OperationType
    static mappedBy = [operationTypes:'followings']
    static mapping = {
        ...
        id composite: ['offer', 'user']
        offer column: 'offer_oid'
        user column: 'user_oid'
        operationTypes joinTable: [name: 'operationtype_following', key: ['favorite_user_offer_oid', 'favorite_user_user_oid']]
    }
}

和:

class OperationType implements Serializable {
    ...
    static hasMany = [offers:Offer, advices:Advice, followings:Following]
    static mappedBy = [followings:'operationTypes']
    static mapping = {
        ....
        followings joinTable: [name: 'operationtype_following', key: 'operationtype_oid']
    }
}

结果:映射异常:外键(FK_lhri681gwbef5a9y6ylhoakpj:operationtype_following[foldite_user_offer_oid,preferente_user_user_oid,following_offer_id,Folowing_user_id])必须具有与引用主键(preferente_user[user_oid,offer_oid])相同的列数

那么,为什么它不真正忽略列名,而是将生成的列名添加到指定的列名中呢?

使用Grails 2.4.3。感谢的任何帮助

我能够在m:m关系中使用复合外键。这使用以下映射语法。SITE和MACHINE_FK是联接表的属性。

static mapping = {
        mstAttributeList {
            column name: 'SITE'
            column name: 'MACHINE_FK', sqlType: 'nvarchar2'             
        }           
        mstAttributeList joinTable: [name: 'MST_MACHINE_ATTRIBUTE', key: ['MACHINE_FK', 'SITE']]
}
static hasMany = [ mstAttributeList : com.gknsintermetals.mda.master.MstAttribute ]

最新更新