我是一个不稳定的我addTo *方法,我有一个记录,不断有必要在一个实例中的关系信息。问题是,当我在短时间内放置多个插入时,它们不再持久存储在数据库中,而是在它们返回之后,它们只是被放弃时间。Grails的行为方法AddTo *
我的简单课程是'发生'和'监测',每当我打电话时我必须注册它,它发生在连续两次记录上,第三次不再存在于数据库中,我失去了记录。
Class Occurrence implements Serializable{
...
hasMany = [accompaniments: Monitoring]
...
}
Class Monitoring implements Serializable{
...
belongsTo = [occurrence : Occurrence]
...
}
有控制器看起来是这样的:
def regMonitoring(Long id){
def chamadoInstance = Occurrence.get(id)
if (!chamadoInstance) {
flash.message = message(code: 'default.not.found.message', args: [message(code: 'Occurrence .label', default: 'Occurrence '), id])
return
}
chamadoInstance.status = StatusChamado.findByCodigo("MOV")
if (!chamadoInstance.save(flush: true)) {
render(view: "editMonitoring", model: [chamadoInstance: chamadoInstance])
return
}
def mov = chamadoService.regMonitoring("") //returns an instance of Customer with preset output values .
chamadoInstance.addToAccompaniments (mov)
redirect(action: "showChamado", id: chamadoInstance.id)
}
addToAccompaniments后添加chamadoInstance.save(flush:true)。 –
解决了问题!谢谢!我意识到,在这个变化之前,它第一次被实例化并且在第三个实例没有被持久化之后。我想知道为什么发生这种情况 – isilva
很高兴它解决了这个问题(作为答案添加,所以你可以接受和upvote它)。 –