本文介绍了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.

也在Grails邮件列表中表示过(见)使用 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不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 06:58
查看更多