开发者

How can I change column name convention in Grails?

For now I have field "String firstNa开发者_高级运维me" it converted to "first_name" and i want "firstname" as default in Hibernate. Is it posible?


5.5.2.1 Table and Column Names

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


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜