问题描述
我有一个使用mongoDB的Grails应用程序,该应用程序运行一长段代码,最后会更新域类。由于这段代码是同时运行的,所以我要花很多OptimisticLockingException
。
为避免这种情况,我决定执行以下操作:
def method(Vehicle vehicle) {
// long read only code using vehicle's properties
synchronyzed(lock) {
vehicle.refresh()
vehicle.property = newValue
vehicle.save()
}
}
不幸的是,refresh
方法并未在MongoDB的GORM上实现,并抛出了java.lang.UnsupportedOperationException: Refresh not supported by codec entity persistence engine
。
我还尝试了以下方法:
def method(Vehicle vehicle) {
// long read only code using vehicle's properties
synchronyzed(lock) {
vehicle = Vehicle.get(vehicle.id)
vehicle.property = newValue
vehicle.save()
}
}
但是看起来好像有某种会话可以返回与Hibernate的L1缓存相同的对象。
是否可以刷新此实例?
PS:我知道我可以将类切换到stateless模式,但这需要大量的重构,有状态模式对我的用例来说更好,除了这段代码。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)