I'm trying to create a pair of GORM domain objects with a one-to-one mapping with the caveat that the key between the two tables is not a long, but instead a UUID string/varchar. I've looked all over for discussions on how to do this in grails/gorm, and found a few questions, but no answers of use. Here are my two classes, I hope someone can point me in a reasonable direction.
Thanks.
class ItemLastChange {
static belongsTo = [item: Item]
static mapping = {
cache true
version false
id column: 'item_hash_msb', name: 'itemHashMsb'
item column: 'item_uuid', key: 'uuid', sqlType: 'text', type: 'text', insertable: false, updateable: false
}
static constraints = {
}
long itemHashMsb;
String itemUuid;
String itemMapCode;
String dbActionType;
String version;
Calendar modificationDate;
}
class Item {
static hasOne = [itemLastChange: ItemLastChange]
static mapping = {
cache true
version false
id column:'item_id'
columns {
itemLastChange column: 'uuid', lazy: false, key: 'item_uuid', type: 'text', insertable: false, updateable: false
}
}
static constraints = {
}
ItemLastChange itemLastchange
long id
String uuid
//other fields eliminated
}
... for reasons relating to existing data and tables, etc. having the ItemLastChange table utilize the item_id as the FK is not a doable solution (as much as we all wish it was...)
This results in the following error:
java.sql.SQLException: Invalid value for getLong() - '6890daf634873fbaac307cad258561be'
Where the value '6890daf634873fbaac307cad258561be' is the varchar UUID from the ItemLastChange table.
Per comments below, here's a rough schema:
Item
----
Field Type * Collation Null Key
item_id int(11) NO PRI
item_type_id int(11) {null} YES MUL
organization_id int(11) {null} YES MUL
item_map_code varchar(36) utf8_bin YES
uuid char(32) utf8_bin NO UNI
name varchar(64) utf8_bin NO
...
ItemLastChange
--------------
Field Type Collation Null Key
item_hash_msb bigint(20) NO PRI
item_uuid varchar(32) utf8_bin NO UNI
item_map_code varchar(36) utf8_bin NO
db_action_type varchar(64) utf8_bin NO
item_version varchar(16) utf8_bin NO
description longtext utf8_bin YES
ine_app_version varchar(16) utf8_bin YES
creation_date datetime NO
modification_date datetime NO
There is no defined FK relationship between these tables.
Thanks in advance.
-Steighton