RaceRegistration域已嵌入raceParticipant,raceParticipant有一個字段bibNumber,它是Integer。爲什麼save()不保存數據並保存(flush:true)是必需的?
我有一個方法,用於清空註冊的所有bibNumbers,但沒有刷新:true保存,無效的圍兜不起作用。圍兜沒有設置爲空。
def nullifyBibNumbers(Long id){
...
def regss = RaceRegistration.createCriteria().list(){
eq('compositeEvent', event)
}
regss.each{ r ->
r.raceParticipant.bibNumber = null
r.save()
}
render "Bibs resetted!"
}
如果我添加flush:true,則圍兜被設置爲null。
regss.each{ r ->
r.raceParticipant.bibNumber = null
r.save(flush: true)
}
我想知道爲什麼你需要flush以便將值設置爲null?我猜測問題是關於我如何使用createCriteria()獲取註冊列表。我很感謝我面臨的這個困境。謝謝!
爲什麼save()不保存數據並flush:true是必需的?由於大量的記錄,我無法使用flush:true。 – kofhearts
就像我剛纔所說:save()**將**保存數據,但不一定立即。請注意,我們正在討論這裏的更新,數據庫中已存在數據。新實例(即DB插入)的保存將立即生效。 –
我在方法完成後檢查數據。方法完成後應該有數據嗎? – kofhearts