grails - 如何更改 Grails 嵌入的列映射

标签 grails grails-orm

我正在研究将我的应用程序的持久性映射从 hibernate hbm 文件移动到 grails 域对象。该模式不符合 Grails 的许多列命名约定,包括组合列名称。我想做的是:

class Foo{
   Bar bar
   static embedded = ['bar']
   static mapping = {
         bar.baz column:'baz'
         bar.quz column:'qux'
   }
}

class Bar{
  String baz, qux
}

jira对于这个问题。不幸的是,它已经开放了近两年没有任何变化。是否有解决方法无法更改数据库中的列?

最佳答案

而不是使用嵌入变量为您的 Bar 类创建一个自定义的休眠 UserType。然后,您可以将该自定义类型映射到您想要的任何列名称:

static mapping = {
    bar type: BarUserType, { 
        column name: "bar"
        column name: "quz"
    }
}

关于grails - 如何更改 Grails 嵌入的列映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9592580/

相关文章:

grails - grails中设置Quartz的repeatInterval的值

mysql - Grails MySQL 最大池大小

hibernate - withTransaction 并保存大量对象?

mapping - GORM 与一列映射的两个字段抛出异常 ...insert ="false"update ="false"

在 Grails 中缓存?

grails - 如何在<g:datepicker/> grails和groovy中仅显示 “hour”和 “minute”?

hibernate - 何时在 grails 中使用executeUpdate

grails - 在 Bootstrap.groovy 中设置 Grails 域 ID

Grails 数据绑定(bind) - 无法修改不可变实体

grails - 在Grails审核日志记录插件的onChange方法中,如何获得对拥有的可审核域对象的引用?