【问题标题】:GORM Inheritance column definition mappingGORM 继承列定义映射
【发布时间】:2014-02-06 14:02:35
【问题描述】:

大家好,

我有两个表(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 中的新)

有什么想法吗?

【问题讨论】:

  • 它适用于安德鲁。感谢您的快速回答!

标签: grails inheritance grails-orm


【解决方案1】:

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

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

Link to ref docs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 2017-12-07
    • 2011-11-22
    • 2010-11-25
    • 1970-01-01
    相关资源
    最近更新 更多