org.hibernate.StaleObjectStateException:行被另一个事务更新或删除(或未保存的值映射不正确)

org.hibernate.StaleObjectStateException:行被另一个事务更新或删除(或未保存的值映射不正确),hibernate,grails,gorm,Hibernate,Grails,Gorm,我知道这个错误在这里很常见。但我只是不明白为什么我试图删除一个实例时会发生这种情况 <g:form url="[resource:scholarshipsForPeriodInstance, action:'delete']" method="DELETE"> <fieldset class="buttons"> <g:link class="edit" action="edit" resource="${sc

我知道这个错误在这里很常见。但我只是不明白为什么我试图删除一个实例时会发生这种情况

<g:form url="[resource:scholarshipsForPeriodInstance, action:'delete']" method="DELETE">
            <fieldset class="buttons">
                <g:link class="edit" action="edit" resource="${scholarshipsForPeriodInstance}"><g:message code="default.button.edit.label" default="Edit" /></g:link>
                <g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" />
            </fieldset>
        </g:form>
所以我打开了logSql

Hibernate: delete from scholarships_for_period where id=? and version=?
Hibernate: update scholarships_for_period set version=?, application_name_id=?, apply_direct=?, donor_id=?, percentage_of_amount=?, period_id=?, restriction=?, total_amount=? where id=? and version=?
为什么Hibernate会话在我删除此实例后尝试更新?如果有任何帮助,我将不胜感激。谢谢

==== 更新: 非常有趣的是,当我将“重定向”更改为“渲染”或“转发”时,不会出现错误,实例也会被删除。为什么

@Transactional
def delete(ScholarshipsForPeriod scholarshipsForPeriodInstance) {
    if (scholarshipsForPeriodInstance == null) {
        notFound()
        return
    }

    scholarshipsForPeriodInstance.delete flush: true
    forward action: "index" //or render 'ok'
}

删除对象后,您正在使用资源scholarshipsForPeriodInstance.id-删除后,您不应再寻址该对象

您向方法发送的不仅仅是
id
属性吗?可能是您正在发送其他属性,这些属性会使实例变脏,而OSIV(视图中的打开会话)会尝试持久化该实例。谢谢,脏实例是什么意思。我如何调试才能找到它?所谓的
脏实例
我的意思是,您已经更改了类实例的一个或多个属性的某些值。在本例中,是绑定到传入HTTP参数的
scholarshipsForPeriodInstance
。首先,我将在控制器内部添加
println params
,查看除了
controller、action和id
之外,还有哪些数据正在发送到控制器。任何与类的属性名称匹配的参数都将设置(绑定)它们的值,从而将实例标记为
dirty
。由于它是脏的,OSIV将在请求结束时尝试保存它。更新:非常有趣的是,当我将“重定向”更改为“呈现”或“转发”时,则不会出现错误,实例将被删除。为什么???谢谢你的回复。“寻址对象”是什么意思。我不认为,我是在删除对象后寻址对象的。您可以将您的代码片段发布到以表明您的观点吗?此行:flash.message=message(代码:'default.deleted.message',args:[消息(代码:'ScholarshipsForPeriod.label',默认:'ScholarshipsForPeriod'),scholarshipsForPeriodInstance.id])使用“scholarshipsForPeriodInstance.id”
@Transactional
def delete(ScholarshipsForPeriod scholarshipsForPeriodInstance) {
    if (scholarshipsForPeriodInstance == null) {
        notFound()
        return
    }

    scholarshipsForPeriodInstance.delete flush: true
    forward action: "index" //or render 'ok'
}