如何从非域类继承GORM映射? [英] How to inherit GORM mapping from non domain class?

查看:173
本文介绍了如何从非域类继承GORM映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

永久地,我有一些表和一些带映射注释的hibernate类。这些类也具有映射注释的抽象超类。但是在这个超类中没有表关联映射。所有表都在子类中标识。
我正尝试将此映射迁移到GORM模型。但所有的策略:TablePerHierarchy和TablePerSubclass不适合我的情况,因为所有的表都是创建的,不能更改。
我在'src / groovy / somepackage /'中创建了超类,并且希望从这个类继承映射和约束到'域'文件夹中的子类。对于约束条件,它工作得很好,但对于映射,我无法找到文档如何做到这一点。
有没有人有任何想法?


$ b 示例



在非域名文件夹中:

  absract class A {
字符串a
静态映射= {
a列:column_A
}
}

在域名文件夹中:

  class B extends A {
String b
static mapping = {
b column:column_B
}

  class C extends A {
String c
static mapping = {
c column:column_C
}
}

需要在每个列中都有'column_A'列。 使用克隆和委托功能是可能的。这是我做的:

  class B extends A {

static mapping = {
def copyMapping = A.mapping.clone()
copyMapping.delegate = delegate
copyMapping.call()
}
}


Permanently I have some tables and some hibernate classes with mapping annotations. And this classes have abstract superclass with mapping annotations also. But in this superclass there is no table association mapping. All tables are identified in the subclasses. I'm trying to migrate this mapping to GORM model. But all strategies: TablePerHierarchy and TablePerSubclass not approach for my case because all tables is created and can't be changed. I created superclass in the 'src/groovy/somepackage/' and want to inherit mapping and constraints from this class to my subclasses in the 'domain' folder. For constraints it works good but for mapping I can't find documentation how to do this. Does anyone have any ideas?

Example.

In the non-domain folder:

absract class A {
  String a
  static mapping = {
    a column: "column_A"
  }
} 

In the domain folder:

class B extends A {
  String b
  static mapping = {
    b column: "column_B"
  }
}

And

class C extends A {
  String c
  static mapping = {
    c column: "column_C"
  }
}

Needs to get two tables with the column 'column_A' in each of them.

解决方案

It's possible using the clone and delegate features. Here's what I did:

class B extends A {

static mapping = {
    def copyMapping = A.mapping.clone()
    copyMapping.delegate = delegate
    copyMapping.call()
    }
}

这篇关于如何从非域类继承GORM映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆