Skip to content

Instantly share code, notes, and snippets.

@aadrian
Created April 21, 2015 09:28
Show Gist options
  • Save aadrian/fad7cab5a477a8951a34 to your computer and use it in GitHub Desktop.
Save aadrian/fad7cab5a477a8951a34 to your computer and use it in GitHub Desktop.
Grails Prefixing all Tables (without changing the mapping of each domain class)
// in "/src/groovy/MyNamingStrategy.groovy"
import org.hibernate.cfg.ImprovedNamingStrategy
/** Override the default naming strategy to support prefixing tables with the "MY_PREFIX_" */
class MyNamingStrategy extends ImprovedNamingStrategy {
String classToTableName(String className) {
"my_prefix_" + super.classToTableName(className)
}
}
// in "/grails-app/conf/DataSource.groovy"
hibernate {
cache.use_second_level_cache = true
// ... other settings ...
naming_strategy = 'MyNamingStrategy'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment