JPA Pessimistic Lock attempt never times out
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