【问题标题】:Grails/GORM Legacy DB One-to-Many mappedBy issueGrails/GORM Legacy DB 一对多映射问题
【发布时间】:2011-03-09 06:17:09
【问题描述】:

我有一个结构相当简单的遗留数据库。我有包含“rollTotals”的“卷”。 Roll 的主键为“rollID”,RollTotals 的主键为“rollID”和“category”。

所以在 Grails 中,我有:

class Roll {
    Integer id
    ...
    static hasMany = [ rollTotals: RollTotal ]
    static mapping = {
        table('rolls')
        id(column:'rollID')
        version false
        ...
    }
}

class RollTotal implements Serializable {
    Integer rollId
    Integer category
    ...
    static belongsTo = [ Roll ]

    static mapping = {
        table('rolltotals')
        id composite:['rollId', 'category']
        version false
        rollId(column:'rollID')
        category(column:'category')
     ...
}

这些映射单独工作正常,但是当我放置 hasMany 时,它说:

缺少的表:rolls_rolltotals

所以我认为它需要知道使用哪一列作为外键,所以我添加到 Roll:

static mappedBy = [rollTotals: "rollId" ]

上面写着:

org.codehaus.groovy.grails.exceptions.GrailsDomainException:为类 [class Roll] 中的属性 [rollTotals] 指定的映射属性 [rollId] 不存在

我尝试使用 rollID(作为列名)但得到了相同的结果。

知道如何链接这些表吗?

【问题讨论】:

    标签: hibernate grails mapping grails-orm


    【解决方案1】:

    尝试将 RollTotal 的 belongsTo 更改为:

    static belongsTo = [roll: Roll]
    

    并添加到 RollTotal 的映射

    roll(column:'rollId')
    

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 1970-01-01
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      • 2022-11-23
      相关资源
      最近更新 更多