Вопрос

If you call lock() on a domain instance or statically on the class, and then you decide there is nothing to do to the object, is there a way to manually and immediately release the lock?

Это было полезно?

Решение

To expand on what dmahapatro said, the docs indicate:

The lock is automatically released when the transaction commits

so once you call .save(), the lock will be released when the transaction for that save commits (typically at end of service method).

You may also want to check out these docs.

Другие советы

Lock is released when the transaction is committed but not when you just call save() because after save() transaction is still alive. Transaction may be committed when code execution leaves service method or when hibernate session is flushed (after http request is finished the session is flushed and cleared).

The best way to release a lock is using manual transaction handling. In service do this:

def saveUser(Long userId)
{
    User.withNewTransaction { TransactionStatus status ->
        User user = User.lock(userId)
        user.save()
    }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top