Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Getting mapping from domain class in Grails
class Person {
Long id
String name
static mapping = {
table name: 'PERSON'
id column: 'PRS_ID'
name column: 'PRS_NAME'
* You can manipulate and collect mapping entries as you wish.
* Here, i reversed mapping entries of Person class.
* Output:
* ['PRS_ID': 'id', 'PRS_NAME': 'name']
def collectedMap = new GrailsDomainBinder().getMapping(Person).columns.collectEntries { key, value ->
[value.columns.get(0).name, key]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.