GORM继承列定义映射

时间:2014-02-06 14:02:36

标签: grails inheritance gorm

Hello evreyone,

我有两张桌子(A和B延伸A)。 A和B是具有指定Id的现有表。 Id(PK)是A和B中的字符串。

使用GORM,如果A和B之间的公共列不是默认列(使用Grails列'id'),我无法映射这两个表。

例如=

class A {
    String acc;
    static mapping = {
        datasource 'xx'
        table "A"
        version false
        tablePerHierarchy false
        id generator: 'assigned', name: 'acc'
        cache 'read-only'
    }

class B extends A {
    String acc;
    static mapping = {
        datasource 'xx'
        table "B"
        version false
        id generator: 'assigned', name: 'acc'
        cache 'read-only'
}

以前的地图有什么问题?

1 / Grails在B表中生成我不想要的Id列。 2 /我无法加载B对象(因为HQL将列acc(表A)链接到列id(表B中的新列)

请问好吗?

1 个答案:

答案 0 :(得分:0)

在您的ID映射中添加column参数:

id generator: 'assigned', name: 'acc', column: 'acc'

Link to ref docs

相关问题