get函數我得到的StringIndexOutOfBoundsException當我嘗試在GORM使用get函數來獲取域類對象。的StringIndexOutOfBoundsException在格姆
域類
class Connect {
int id
long profileid
String username
char type
char superSub
String time
char class_
boolean isapilogin
static mapping = {
table "CONNECT"
version false
id column: "ID"
profileid column: "PROFILEID"
username column: "USERNAME"
type column: "TYPE"
superSub column: "SUPER_SUB"
time column: "TIME"
class_ column: "CLASS"
isapilogin column: "ISAPILOGIN"
}
static constraints = {
username maxSize: 40
type maxSize: 1
superSub maxSize: 1
time maxSize: 14
class_ maxSize: 1
}
}
MySQL數據庫表
ID | int(10)unsigned
PROFILEID | bigint(20)unsigned USERNAME | varchar(40)
TYPE | char(1)
SUPER_SUB | char(1)
TIME | varchar(14)
CLASS | char(1)
ISAPILOGIN | TINYINT(1)
myController的
class DemoController {
def check() {
int id = 1001;
Connect data = Connect.get(id) // exception at this line
data.save()
render "check"
}
}
MySQL表DATA
ID簡檔| USERNAME | TYPE | SUPER_SUB | TIME | CLASS | ISAPILOGIN
1001 | 4 | ABHINAV | | P | 1461235989 | A | 0
1002 | 5 | GAVAN | S | P | 1450155084 | A | 1
當我調用ID 1001而不是ID 1002時,異常即將到來。我認爲的原因是對於ID 1001,類型列具有空值或空間,但對於ID 1002類型具有char值'S'。在我的表中,我有很多空值的行,所以我可以做什麼來避免這種異常?
這是爲什麼?ID是主鍵 –
,因爲GORM自己做它 –
雖然在域中聲明'id'是多餘的,但刪除它並不能解決此問題。 – Armaiti