How to change column name in Grails?

Now I have the field "String firstName", which it is converted to "first_name", and I want the "firstname" to be used by default in Hibernate. Is it possible?

+4
source share
2 answers

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

By default, Grails uses Hibernate's ImprovedNamingStrategy to convert the class of the class. Class and field names for SQL table names and columns. Converts from camel strings to those that use underscores as word separators. You can configure them on the basis of each instance in the mapping, but if there is a template you can specify a different NamingStrategy Class to use.

Set the class name to be used in grails-app / conf / DataSource.groovy in the sleep section, for example

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 } 
+5
source

5.5.2.1 Table and column names

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

All Articles