I'm using custom hibernate types with Grails (http://grails.org/doc/2.3.x/guide/GORM.html#customHibernateTypes) and I'm mapping the type to multiple columns. However, I'm a little stuck on figuring out how to do data binding on these custom types. I can use a @BindUsing annotation, however, I have only one property and multiple columns.
For example here's a groovy class (that will have a custom type that's created using a properly defined CustomDataUserType class):
class CustomData
{
String field1
String field2
}
And here's a domain model that has this class as a property
class DomainModel
{
static mapping = {
customData type: CustomDataUserType, {
column name: "field1"
column name: "field2"
}
@BindUsing { obj, source ->
// The source contains a field/property called customData (otherwise
// this BindUsing closure doesn't get called) however, I need two
// values
}
CustomData customData
}
My problem is that inside the BindUsing closure the source contains one value, a property called customData. However, I need two values to recreate the custom object. How is this problem usually solved?