Grails withNewSession不刷新 [英] Grails withNewSession does not flush

查看:464
本文介绍了Grails withNewSession不刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在grails域中,a已经实现了 beforeDelete ,如下所示:

In a grails Domain a have implemented the beforeDelete as follow

class Shop {
    def beforeDelete() {
        Shop.withNewSession {
            Client.findAllByShop(this)*.shop = null                 
        }    
    }
}

但客户端商店空值不会持久保存到数据库中。

But the client shop null value is not persisted to the DB.

如果我添加一个手动会话刷新

If I add a manual session flush

class Shop {
    def beforeDelete() {
        Shop.withNewSession { s2->
            Client.findAllByShop(this)*.shop = null         
            s2.flush()  
            s2.clear()
        }
    }
}

它的工作原理是,客户商店价值在数据库中为零。

It works, the client shop value are nulled in the db.

这是Grails错误还是我误解了文档? withNewSession 暗示自动刷新?

Is this a Grails bug or I have misunderstand the documentation? Doesn't withNewSession imply an automatic flush?

推荐答案

向下滚动至 beforeDelete 示例这里)似乎暗示不需要刷新或清除会话。

The documentation (scroll down a bit to the beforeDelete example here) seems to imply that flushing or clearing the session is not required.

Burt Beckwith 也在Grails邮件列表中表示过(见清除清除()清除() withNewSession 闭包中不是必需的。

Burt Beckwith has also indicated on the Grails mailing list (see thread here) that manual calls to flush() and clear() aren't necessary in a withNewSession closure.

似乎有一个错误报告(请参阅详细信息此处)使用 withNewSession 从Grails 2.2.1开始。

With that said, there does appear to be a bug report (see details here) using withNewSession starting with Grails 2.2.1.

这篇关于Grails withNewSession不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆