Reputation: 165
I am looking into moving my application's persistence mapping from hibernate hbm files to grails domain objects. The schema does not conform to many of Grails' column naming conventions, including composition column names. What I would want to do is this:
class Foo{
Bar bar
static embedded = ['bar']
static mapping = {
bar.baz column:'baz'
bar.quz column:'qux'
}
}
class Bar{
String baz, qux
}
There is jira for this issue. Unfortunately it's been open for nearly two years with no change. Is there a workaround for this short of changing columns in the db?
Upvotes: 6
Views: 1939
Reputation: 2763
A workaround I have found is to use @grails.util.Mixin instead of embedding:
@grails.util.Mixin(Bar)
class Foo{
static mapping = {
baz column:'bazz'
quz column:'quxx'
}
}
class Bar{
String baz, qux
}
Upvotes: 0
Reputation: 628
Instead of using the embedded variable create a custom hibernate UserType for your Bar class. You can then map that custom type to whichever column names you want like:
static mapping = {
bar type: BarUserType, {
column name: "bar"
column name: "quz"
}
}
Upvotes: 3
Reputation: 3739
I believe the only way is currently (grails 2.1) to put the mapping in Bar,
class Bar {
String bar, quz
static mapping = {
baz column: "baz"
quz column: "quz"
}
}
Upvotes: 2