0

他の人がこの問題を抱えているのを見てきましたが、私の場合にうまくいく解決策をまだ見つけていません. 私のドメイン コントローラの update メソッドでは、バージョンをチェックして rejectValue(); を使用して、楽観的ロックを実装しようとしています。しかし、私は明らかに何か間違ったことをしています。rejectValue() が呼び出されていることを確認しましたが、機能していないようです。

また、不良データを含むドメイン インスタンスはいずれにせよ保存されます。アドバイスやヘルプをいただければ幸いです。問題のある私の更新方法は次のとおりです。

def update(Cohort cohortInstance) {
    if (cohortInstance == null) {
        notFound()
        return
    }

    cohortInstance = Cohort.get(params.id)
    if (cohortInstance == null) {
        notFound()
        return
    }

   if (params.version) {
        def version = params.version.toLong()
        if (cohortInstance.version > version) {
            cohortInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
                      [message(code: 'cohort.label', default: 'Cohort')] as Object[],
                      "Another user has updated this Cohort while you were editing")
            render(view: "edit", model: [cohortInstance: cohortInstance])
            return
        }
    }

    // Bind browser data to this cohort Instance now that we've passed the concurrency check
    cohortInstance.properties = params

    if (cohortInstance.hasErrors()) {
        respond cohortInstance.errors, view:'edit'
        return
    }

    cohortInstance.save flush:true

    request.withFormat {
        form multipartForm {
            flash.message = message(code: 'default.updated.message', args: [message(code: 'Cohort.label', default: 'Cohort'), cohortInstance.proposedCode])
            redirect cohortInstance
        }
        '*'{ respond cohortInstance, [status: OK] }
    }
}
4

1 に答える 1