如何从数据库中刷新MongoDB的GORM对象?
我有一个使用mongoDB的Grails应用程序,它运行一段很长的代码,最后更新了一个域类。由于这段代码同时运行,我正在处理大量的如何从数据库中刷新MongoDB的GORM对象?,mongodb,grails,gorm,gorm-mongodb,Mongodb,Grails,Gorm,Gorm Mongodb,我有一个使用mongoDB的Grails应用程序,它运行一段很长的代码,最后更新了一个域类。由于这段代码同时运行,我正在处理大量的OptimisticLockingExceptions 为了避免这种情况,我决定如下所示: def method(Vehicle vehicle) { // long read only code using vehicle's properties synchronyzed(lock) { vehicle.refresh()
OptimisticLockingException
s
为了避免这种情况,我决定如下所示:
def method(Vehicle vehicle) {
// long read only code using vehicle's properties
synchronyzed(lock) {
vehicle.refresh()
vehicle.property = newValue
vehicle.save()
}
}
def method(Vehicle vehicle) {
// long read only code using vehicle's properties
synchronyzed(lock) {
vehicle = Vehicle.get(vehicle.id)
vehicle.property = newValue
vehicle.save()
}
}
不幸的是,refresh
方法没有在GORM for MongoDB上实现,并抛出java.lang.UnsupportedOperationException:codec实体持久性引擎不支持刷新
我还尝试了以下方法:
def method(Vehicle vehicle) {
// long read only code using vehicle's properties
synchronyzed(lock) {
vehicle.refresh()
vehicle.property = newValue
vehicle.save()
}
}
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的一级缓存相同的对象
是否有方法刷新此实例
PS:我知道我可以将类切换到模式,但这需要一个巨大的重构,而有状态模式对我的用例更好,除了这段代码