【发布时间】:2019-09-20 19:44:49
【问题描述】:
This 文章内容如下:
Product.withTransaction{
product.status = "ACTIVE"
product.save(flush:true) //without this line the total number will be all of them but this one
Product.countByStatus("ACTIVE")
}
不清楚的部分是以下注释:
如果没有这一行,总数将是所有这些,但这一行
以及上面代码后面的文章中的解释:
在没有强制flush:true的前面代码中,我们会省略我们在交易中保存的产品。
根据我的理解,如果我们调用product.save()(不刷新),product 实例应该附加到 Hibernate 会话,成为一个persistent 实体,它应该包含在Product.countByStatus("ACTIVE") 返回的数字中事务与我们保存产品的地方相同,即使指令未刷新到数据库,休眠会话也包含该已保存产品的信息。
【问题讨论】:
标签: hibernate grails grails-orm