JPA Pessimistic Lock attempt never times out

后端 未结 3 601
悲&欢浪女
悲&欢浪女 2021-01-05 09:34

I\'m trying to use Pessimistic locking in JPA, over Hibernate 3 against a Postgres Database. I can\'t get the lock to time out - it just seems to hang forever.

Here

3条回答
  •  孤城傲影
    2021-01-05 10:05

    Postgres SELECT for update syntax only provides the options to not wait if a lock can not be obtained right away. See postgres docs.

    To prevent the operation from waiting for other transactions to commit, use the NOWAIT option. With NOWAIT, the statement reports an error, rather than waiting, if a selected row cannot be locked immediately. Note that NOWAIT applies only to the row-level lock(s) — the required ROW SHARE table-level lock is still taken in the ordinary way (see Chapter 13). You can use LOCK with the NOWAIT option first, if you need to acquire the table-level lock without waiting.

    When working with postgres I have observed that any value over 0 for the timeout will cause hibernate to issue SELECT FOR UPDATE but when timeout is 0 it will issue SELECT FOR UPDATE NO WAIT

提交回复
热议问题