Be careful when reusing Hibernate domain model in Grails

In one of my projects I am using Grails to create a simple crud management UI for an Spring MVC app. Because Grails allows to reuse the existing Hibernate domain model of the Spring app this saved a lot time.

Last week I suddenly found out that Grails was using a different naming strategy when mapping the model to the database. In my case I wanted to let Grails create the tables for the Spring Security plugin so I activated the hbm2ddl update. When starting the app it created all the tables in my database with in lowercase and with underscores instead of camel case naming.

I found out that Grails was using the ImprovedNamingStrategy instead of the DefaultNamingStrategy Hibernate used in my app. So I had to add the following configuration to the DataSource.groovy file:

hibernate {
  naming_strategy=org.hibernate.cfg.DefaultNamingStrategy
}

UPDATE: I wrote another post on this topic!