3
當我嘗試鎖定表中的一行時,有時會返回null。那是什麼意思?我驗證域的實例是不是空鎖之前:GPars鎖返回null
println state
state = State.lock(state.id)
println state
此輸出:
State 1
null
(「國1」狀態的字符串表示)
當我嘗試鎖定表中的一行時,有時會返回null。那是什麼意思?我驗證域的實例是不是空鎖之前:GPars鎖返回null
println state
state = State.lock(state.id)
println state
此輸出:
State 1
null
(「國1」狀態的字符串表示)
這樣做你從GORM樂觀鎖定(它在更新之前比較對象的版本)切換到悲觀鎖定,這意味着讀取操作將被阻止,直到鎖定被釋放。如果你想檢索值(參見方法的returnValue)使用封閉下面:
State.withPessimisticLock(state.id) { Object lockedDomain ->
return "OK"
}.onNotFound { ->
return "NG"
}
assert result.returnValue == "OK"
順便說一句,需要一個事務,所以這是你的問題返回null
可能意味着你的目標是出了交易。