Sto provando a creare una coppia di oggetti dominio GORM con una mappatura uno-a-uno con l'avvertenza che la chiave tra le due tabelle non è un lungo, ma invece una stringa UUID/varchar. Ho cercato dappertutto discussioni su come farlo in Grails/gorm e ho trovato alcune domande, ma nessuna risposta d'uso. Ecco le mie due classi, spero che qualcuno possa indicarmi una direzione ragionevole.GORM: mappatura tabella uno-a-uno usando la stringa come chiave
Grazie.
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
}
... per motivi legati ai dati e tabelle esistenti, ecc avendo il tavolo ItemLastChange utilizzare l'item_id come il FK non è una soluzione fattibile (tanto quanto noi tutti desideriamo che era ...)
il risultato è il seguente errore:
java.sql.SQLException: valore non valido per getLong() - '6890daf634873fbaac307cad258561be'
Quando il valore '6890daf634873fbaac307cad258561be' è l'UUID varchar dalla tabella ItemLastChange.
Per commenti qui sotto, ecco uno schema di massima:
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
Non esiste alcuna relazione FK definita tra queste tabelle.
Grazie in anticipo.
-Steighton
post lo schema delle tabelle. –
Che errore ottieni? –
Scusa, ho evitato questo problema per un minuto ... (e in qualche modo non ho visto le tue risposte ... comunque, l'errore che ottengo è: java.sql.SQLException: valore non valido per getLong() - '6890daf634873fbaac307cad258561be' Sembra che dal momento che la relazione è definita da una chiave varchar che il sistema presuppone che la colonna per la relazione * deve * essere lunga. –