如何更改 Grails 中的列名称约定?

发布于 2024-09-24 01:12:10 字数 87 浏览 10 评论 0原文

现在我有字段“String firstName”,它转换为“first_name”,我希望“firstname”作为 Hibernate 中的默认值。有可能吗?

For now I have field "String firstName" it converted to "first_name" and i want "firstname" as default in Hibernate. Is it posible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙厌世 2024-10-01 01:12:10

5.5.2.1 表和列名称

class Person {
  String firstName
  static mapping = {
      table 'people'
      firstName column:'firstname'
  }
}

5.5.2.1 Table and Column Names

class Person {
  String firstName
  static mapping = {
      table 'people'
      firstName column:'firstname'
  }
}
长梦不多时 2024-10-01 01:12:10

您可以更改整个项目的命名策略。从文档 https://grails.github.io/grails -doc/latest/guide/GORM.html#customNamingStrategy

默认情况下 Grails 使用 Hibernate
改进的命名策略转换
域类 类和字段名称
SQL 表名和列名
从驼峰式字符串转换为
使用下划线作为单词的
分隔符。您可以自定义这些
映射中的每个实例基础
关闭但如果有一个一致的
您可以指定不同的模式
要使用的 NamingStrategy 类。

在hibernate部分的grails-app/conf/DataSource.groovy中配置要使用的类名,例如

,在 DataSource.groovy 中类似这样的内容

dataSource {
    pooled = true
    dbCreate = "create-drop"
     …
}
hibernate {
    cache.use_second_level_cache = true
     …
    naming_strategy = org.hibernate.cfg.DefaultNamingStrategy
}

You can change the naming strategy for the entire project. From the documentation https://grails.github.io/grails-doc/latest/guide/GORM.html#customNamingStrategy.

By default Grails uses Hibernate's
ImprovedNamingStrategy to convert
domain class Class and field names to
SQL table and column names by
converting from camel-cased Strings to
ones that use underscores as word
separators. You can customize these on
a per-instance basis in the mapping
closure but if there's a consistent
pattern you can specify a different
NamingStrategy class to use.

Configure the class name to be used in grails-app/conf/DataSource.groovy in the hibernate section, e.g.

So, something like this in your DataSource.groovy

dataSource {
    pooled = true
    dbCreate = "create-drop"
     …
}
hibernate {
    cache.use_second_level_cache = true
     …
    naming_strategy = org.hibernate.cfg.DefaultNamingStrategy
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文