Grails GORM: How do I create a composite primary key and use it for a table relationship?

前端 未结 3 594
执念已碎
执念已碎 2021-01-22 01:26

I have two tables, one of which (legacy table: A) has two fields that should serve as a composite foreign key and the other one (new table: B) should use a composite primary key

3条回答
  •  -上瘾入骨i
    2021-01-22 01:32

    Did you try to use attribute name instead of use attribute value ?

    class B implements Serializable{
        String name;
        String className;
        String eventName;
    
        static mapping = {
            //supposed to make a composite PK
            id composite:['className', 'eventName'] 
        }
    }
    

    And mapping in A :

    class A {
        static hasMany = [ b : B ]
    }
    

    No need to have className or eventName in A

提交回复
热议问题