GORM doesn't handle mapping of associations which have a further association in their composite primary key

半世苍凉 提交于 2019-12-08 20:55:31

try:

Child

class Child implements Serializable {

    String name

    static belongsTo= [parent: Parent]

    static mapping= {
        id(composite: ['parent', 'name'])
    }
}

Parent

class Parent implements Serializable {
    String name

    //static belongsTo= [parent: Parent]  //why do you need this
    static belongsTo= [GrandParent  ]  //did you mean this
    static hasMany= [children: Child,grandParent: GrandParent  ]

    static mapping= {
        id(composite: ['grandParent', 'name'])
    }
}

GrandParent

class GrandParent implements Serializable {
    String name
    Integer luckyNumber

    static hasMany= [parents: Parent]

    static mapping= {
        id(composite: ['name', 'luckyNumber'])
    }
}

I've asked around on Grails Slack #gorm, and this appears to hit a gap in Gorm mapping.

I've raised an issue in the Grails data mapping project. We'll see where this goes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!