Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/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
如何从数据库中刷新MongoDB的GORM对象?_Mongodb_Grails_Gorm_Gorm Mongodb - Fatal编程技术网

如何从数据库中刷新MongoDB的GORM对象?

如何从数据库中刷新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()

我有一个使用mongoDB的Grails应用程序,它运行一段很长的代码,最后更新了一个域类。由于这段代码同时运行,我正在处理大量的
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:我知道我可以将类切换到模式,但这需要一个巨大的重构,而有状态模式对我的用例更好,除了这段代码