grails - 如何强制 Grails GORM 从数据库中检索信息(.refresh() 不起作用)
问题描述
我有一个问题,在 Grails 中,我在数据库记录上设置了一个标志——另一个进程看到了这个标志并更新了记录状态,然后我在 grails 中循环遍历这条记录以获取更改的状态。
问题是 grails 永远不会再次从数据库中检索记录,并且总是将我第一次获取的记录返回给我。我试过了.refresh()
.withNewTransaction()
,.withNewSession
但都没有成功。
所以我的主要问题是如何强制 gorm 从数据库中重新获取我的实例
以下是我的代码不起作用:
MyDomain.withNewTransaction {
MyDomain myDomainInstance = MyDomain.get(params.id);
myDomainInstance.opstatus = 9 /*REQUEST CANCEL OPERATION*/
myDomainInstance.save();
if (myDomainInstance.hasErrors()) {
log.info "Cancel transaction error !: ";
flash.message = message(code: 'error.occured');
render view: "index"
return
}
}
MyDomain myDomainInstance = MyDomain.get(params.id);
while (myDomainInstance.status == Status.SUCCESS.value /*the value should have changed to failed from the other process*/) {
sleep(500);
myDomainInstance.refresh();
}
我添加到日志中
我正在刷新
2018-07-11 16:25:51,850 [http-bio-8080-exec-8] TRACE internal.DefaultRefreshEventListener - Refreshing
2018-07-11 16:25:52,180 [http-bio-8080-exec-8] TRACE internal.DefaultLoadEventListener - Loading entity: [MyDomain#1113507]
2018-07-11 16:25:52,180 [http-bio-8080-exec-8] TRACE internal.DefaultLoadEventListener - Attempting to resolve: [MyDomain#1113507]
2018-07-11 16:25:52,180 [http-bio-8080-exec-8] TRACE internal.DefaultLoadEventListener - Resolved object in session cache: [MyDomain#1113507]
我猜我需要以某种方式清除我的会话缓存?我怎样才能做到这一点
解决方案
推荐阅读
- html - HTML/CSS - css 过滤器是否会创建许多降低网页渲染速度的渲染层?
- javascript - 如何将 Angular 5 Material Select 下拉菜单(mat-select)更改为打字稿代码/文件中的选项之一?
- python - 用于 Rekognition 的端点 URL 的 AWS 连接错误
- jquery - 将 div 转换为表单输入
- triggers - 触发某个帐户记录类型
- tensorflow - ValueError:无法为形状为“(1,)”的张量“Placeholder_765:0”提供形状 (1, 1) 的值
- python - 如何通过执行字符串来获取变量的值?
- c# - 根据“DayOfWeek, Day/Month”查找真实日期
- java - Kurento媒体服务器可以播放某个时间的视频吗?
- c++ - 在 C++ 中与 OpenCV 一起使用 estimateRigidTransform() 时,旋转正确但平移不正确