一直在掙扎着這一段時間。我所試圖做的是建立在Grails的,我有父記錄(的hasMany)標準的關係,這些記錄包含兩列(4,如果再算上ID和版本)Grails:保存孩子記錄失敗了已有的父記錄
定義如下:
class Country {
static hasMany = [regstats: Regstat]
String countryiso
String countryname
static constraints = {
countryiso size:2..2, unique: true, validator:{ it.toUpperCase() == it }
}
static mapping = {
index: 'countryiso'
}
}
這張表很簡單,它包含每個國家的iso3611代碼和它的全名。
第二個包含一堆有關國家的數據,我希望它有孩子/父母的關係。 IE,每個國家可以有多個記錄,但任何時候只能有一個獨特的國家/地區類型。
class Regstat {
static belongsTo = [country: Country]
String reg
int status
String exturl
Date impdate
Date lupdate
String impnote
static constraints = {
reg(inList: ["FATCA", "ITC2014", "AEOI"], unique:'country')
exturl(nullable:true)
impnote(nullable:true)
}
static mapping = {
index: 'reg'
impnote type: 'text'
}
}
我有一個從csv文件加載國家定義的函數,都好,創建了所有243個國家。
然後我嘗試創建子記錄(在不同的功能中,這些國家已保存到數據庫中,已經檢查過)。
運行以下命令:
render ("Writing some stuff<BR>")
render ("To be more precise: ${exturl} ${impdate} ${lupdate} ${impnote} ${ref} ${status} <BR>")
def qp = Country.findByCountryname(cont)
qp.addToRegstats(new Regstat(exturl:exturl, impdate:impdate, lupdate:lupdate,impnote:impnote,reg:ref,status:status))
qp.save(flush:true,failOnError:true)
它倒了沒有盡頭的,我不是很瞭解的輸出是誠實的。 (OK,前兩行是我加的東西,看看是否變量,其中空
Writing some stuff
To be more precise: N/A 2014-06-30 2014-09-29 FATCA 3
Error 500: Internal Server Error
URI
/RegMap/countryupload/loadcsv
Class
grails.validation.ValidationException
Message
Validation Error(s) occurred during save(): - Field error in object 'regmap.Country' on field 'regstats[0].impdate': rejected value [null]; codes [regmap.Regstat.impdate.nullable.error.regmap.Country.regstats[0].impdate,regmap.Regstat.impdate.nullable.error.regmap.Country.regstats.impdate,regmap.Regstat.impdate.nullable.error.regstats[0].impdate,regmap.Regstat.impdate.nullable.error.regstats.impdate,regmap.Regstat.impdate.nullable.error.impdate,regmap.Regstat.impdate.nullable.error.java.util.Date,regmap.Regstat.impdate.nullable.error,regstat.impdate.nullable.error.regmap.Country.regstats[0].impdate,regstat.impdate.nullable.error.regmap.Country.regstats.impdate,regstat.impdate.nullable.error.regstats[0].impdate,regstat.impdate.nullable.error.regstats.impdate,regstat.impdate.nullable.error.impdate,regstat.impdate.nullable.error.java.util.Date,regstat.impdate.nullable.error,regmap.Regstat.impdate.nullable.regmap.Country.regstats[0].impdate,regmap.Regstat.impdate.nullable.regmap.Country.regstats.impdate,regmap.Regstat.impdate.nullable.regstats[0].impdate,regmap.Regstat.impdate.nullable.regstats.impdate,regmap.Regstat.impdate.nullable.impdate,regmap.Regstat.impdate.nullable.java.util.Date,regmap.Regstat.impdate.nullable,regstat.impdate.nullable.regmap.Country.regstats[0].impdate,regstat.impdate.nullable.regmap.Country.regstats.impdate,regstat.impdate.nullable.regstats[0].impdate,regstat.impdate.nullable.regstats.impdate,regstat.impdate.nullable.impdate,regstat.impdate.nullable.java.util.Date,regstat.impdate.nullable,nullable.regmap.Country.regstats[0].impdate,nullable.regmap.Country.regstats.impdate,nullable.regstats[0].impdate,nullable.regstats.impdate,nullable.impdate,nullable.java.util.Date,nullable]; arguments [impdate,class regmap.Regstat]; default message [Property [{0}] of class [{1}] cannot be null] - Field error in object 'regmap.Country' on field 'regstats[0].lupdate': rejected value [null]; codes [regmap.Regstat.lupdate.nullable.error.regmap.Country.regstats[0].lupdate,regmap.Regstat.lupdate.nullable.error.regmap.Country.regstats.lupdate,regmap.Regstat.lupdate.nullable.error.regstats[0].lupdate,regmap.Regstat.lupdate.nullable.error.regstats.lupdate,regmap.Regstat.lupdate.nullable.error.lupdate,regmap.Regstat.lupdate.nullable.error.java.util.Date,regmap.Regstat.lupdate.nullable.error,regstat.lupdate.nullable.error.regmap.Country.regstats[0].lupdate,regstat.lupdate.nullable.error.regmap.Country.regstats.lupdate,regstat.lupdate.nullable.error.regstats[0].lupdate,regstat.lupdate.nullable.error.regstats.lupdate,regstat.lupdate.nullable.error.lupdate,regstat.lupdate.nullable.error.java.util.Date,regstat.lupdate.nullable.error,regmap.Regstat.lupdate.nullable.regmap.Country.regstats[0].lupdate,regmap.Regstat.lupdate.nullable.regmap.Country.regstats.lupdate,regmap.Regstat.lupdate.nullable.regstats[0].lupdate,regmap.Regstat.lupdate.nullable.regstats.lupdate,regmap.Regstat.lupdate.nullable.lupdate,regmap.Regstat.lupdate.nullable.java.util.Date,regmap.Regstat.lupdate.nullable,regstat.lupdate.nullable.regmap.Country.regstats[0].lupdate,regstat.lupdate.nullable.regmap.Country.regstats.lupdate,regstat.lupdate.nullable.regstats[0].lupdate,regstat.lupdate.nullable.regstats.lupdate,regstat.lupdate.nullable.lupdate,regstat.lupdate.nullable.java.util.Date,regstat.lupdate.nullable,nullable.regmap.Country.regstats[0].lupdate,nullable.regmap.Country.regstats.lupdate,nullable.regstats[0].lupdate,nullable.regstats.lupdate,nullable.lupdate,nullable.java.util.Date,nullable]; arguments [lupdate,class regmap.Regstat]; default message [Property [{0}] of class [{1}] cannot be null]
Around line 66 of grails-app/controllers/regmap/CountryuploadController.groovy
63: render ("To be more precise: ${exturl} ${impdate} ${lupdate} ${impnote} ${ref} ${status} <BR>")
64: def qp = Country.findByCountryname(cont)
65: qp.addToRegstats(new Regstat(exturl:exturl, impdate:impdate, lupdate:lupdate,impnote:impnote,reg:ref,status:status))
66: qp.save(flush:true,failOnError:true)
更新: 對於它的樂趣,我設置兩個日期可空爲好,然後我得到了潛在的至少有幫助的錯誤消息不斷 URI
/RegMap/countryupload/loadcsv
Class
java.lang.NullPointerException
Message
null
而且我確實做到了這對同期增長檢查續存在的數據庫相同的檢查。
EDIT 2 改變了渲染線,使人們可以看到什麼是每個變量: 得到這個消息(當impdate,impnote,exturl和lupdate爲空)
Writing some stuff
To be more precise: exturl:N/A impdate:2014-06-30 update:2014-09-29 impdate: ref:FATCA status:3
Error 500: Internal Server Error
URI
/RegMap/countryupload/loadcsv
Class
java.lang.NullPointerException
Message
null
保存調用失敗,因爲數據驗證失敗,因爲國家的impdate不能爲空。 – sebnukem 2014-09-30 20:56:25
至於將日期設置爲空的步驟之後的第二個錯誤,請嘗試重新啓動您的應用,然後嘗試'grails clean'並重新啓動。 – sebnukem 2014-09-30 20:58:11
這是我無法理解的,日期不爲空,我把它稱爲行前。有一個快速檢查,這絕對是正確的,但認爲是。 – vrghost 2014-09-30 20:58:46