我有一个问题,在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]
我猜我需要以某种方式清除会话缓存?我该怎么办