Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate 何时在grails中保存实例?_Hibernate_Grails_Gorm - Fatal编程技术网

Hibernate 何时在grails中保存实例?

Hibernate 何时在grails中保存实例?,hibernate,grails,gorm,Hibernate,Grails,Gorm,在grails中保存实例的准则是什么 我正在做这样的事情: def colorInstance = Color.findOrSaveByName(colorname) if (colorInstance.startsWith("R")) { colorInstance.isRColor = true; } 我是否应该在if块中调用colorInstance.save()?为什么呢?只要流程需要,就可以显式保存实例(正如您的示例所示) 假设在请求周期结束时,当刷新GORM会话时,执行脏检查

在grails中保存实例的准则是什么

我正在做这样的事情:

def colorInstance = Color.findOrSaveByName(colorname)
if (colorInstance.startsWith("R")) {
   colorInstance.isRColor = true;
}

我是否应该在if块中调用
colorInstance.save()
?为什么呢?

只要流程需要,就可以显式保存实例(正如您的示例所示)

假设
在请求周期结束时,当刷新GORM会话时,执行脏检查操作。将绑定到会话的对象与其原始值进行比较,如果检测到更改,则将保留这些对象


从中,阅读有关休眠会话的段落

在Grails2.3.4
colorInstance.save flush:true中


在Grails2.2.2
colorInstance.save(flush:true)

中,使用类似的parathens与grails版本无关,而且它们的工作原理相同,无论如何,这并不能真正回答问题