How to change Grails built-in column mappings

I am exploring the transfer of application persistence mapping from hibernate hbm files to grails domain objects. The schema does not comply with many Grails column naming conventions, including composition column names. I would like to do the following:

class Foo{
   Bar bar
   static embedded = ['bar']
   static mapping = {
         bar.baz column:'baz'
         bar.quz column:'qux'
   }
}

class Bar{
  String baz, qux
}

jira for this problem. Unfortunately, it was opened for almost two years unchanged. Is there a workaround for this without changing the columns in db?

+5
source share
3 answers

Instead of using the built-in variable, create a hibernate UserType for your Bar class. Then you can map this custom type to whatever column name you want:

static mapping = {
    bar type: BarUserType, { 
        column name: "bar"
        column name: "quz"
    }
}
+2
source

, (grails 2.1) Bar,

class Bar {
    String bar, quz

    static mapping = {
        baz column: "baz"
        quz column: "quz"
    }
}
+1

The workaround I found is to use @ grails.util.Mixin instead of nesting:

@grails.util.Mixin(Bar)
class Foo{
   static mapping = {
         baz column:'bazz'
         quz column:'quxx'
   }
}

class Bar{
  String baz, qux
}
0
source

All Articles