3

When I try to lock a line in my table, sometimes null is returned. What does that mean? I verify that the domain instance was not null before the lock:

println state
state = State.lock(state.id)
println state

This outputs:

State 1
null

("State 1" is the String representation of state)

Alison
  • 5,630
  • 4
  • 18
  • 26

1 Answers1

0

By doing this you're switching from GORM optimistic locking (which compares version of your object before your update ) by a pessimitic lock which implies that read operations will be blocking until the lock is released. Use the closure below if you want to retrieve a value (see method returnValue):

State.withPessimisticLock(state.id) { Object lockedDomain ->
return "OK"
}.onNotFound { ->
    return "NG"
}
assert result.returnValue == "OK"

By the way, a transaction is required, so the null which is returned in your question probably means your object is out of the transaction.

ludo_rj
  • 3,877
  • 1
  • 18
  • 37