{"record":{"id":"da74a35b6b048990","repo":"hibernate/hibernate-orm","slug":"connection-lock-timeout-does-not-accept-no-wait","errorCode":null,"errorMessage":"Connection lock-timeout does not accept no-wait","messagePattern":"Connection lock-timeout does not accept no-wait","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/lock/internal/GaussDBLockingSupport.java","lineNumber":134,"sourceCode":"\t\t}\n\t\tcatch (NumberFormatException e) {\n\t\t\tthrow new RuntimeException( e );\n\t\t}\n\t\treturn number;\n\t}\n\n\t@Override\n\tpublic void setLockTimeout(Timeout timeout, Connection connection, SessionFactoryImplementor factory) {\n\t\tHelper.setLockTimeout(\n\t\t\t\ttimeout,\n\t\t\t\t(t) -> {\n\t\t\t\t\tfinal int milliseconds = timeout.milliseconds();\n\t\t\t\t\tif ( milliseconds == SKIP_LOCKED_MILLI ) {\n\t\t\t\t\t\tthrow new HibernateException( \"Connection lock-timeout does not accept skip-locked\" );\n\t\t\t\t\t}\n\n\t\t\t\t\tif ( milliseconds == NO_WAIT_MILLI ) {\n\t\t\t\t\t\tthrow new HibernateException( \"Connection lock-timeout does not accept no-wait\" );\n\t\t\t\t\t}\n\t\t\t\t\treturn milliseconds == WAIT_FOREVER_MILLI\n\t\t\t\t\t\t\t? 0\n\t\t\t\t\t\t\t: milliseconds;\n\t\t\t\t},\n\t\t\t\t\"set local lockwait_timeout = %s\",\n\t\t\t\tconnection,\n\t\t\t\tfactory\n\t\t);\n\t}\n}\n","sourceCodeStart":116,"sourceCodeEnd":146,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/lock/internal/GaussDBLockingSupport.java#L116-L146","documentation":"GaussDBLockingSupport translates a connection lock timeout into 'set local lockwait_timeout = <ms>'. The NO_WAIT sentinel (NO_WAIT_MILLI) is not a duration and cannot be expressed with lockwait_timeout, so requesting no-wait locking through the lock-timeout mechanism throws this HibernateException ('Connection lock-timeout does not accept no-wait').","triggerScenarios":"On GaussDB/openGauss, setting the lock timeout to Timeout.noWait() - e.g. query.setLockTimeout(Timeout.noWait()) or hint 'jakarta.persistence.lock.timeout' = 0 (LockOptions.NO_WAIT) - so that LockTimeoutHandler invokes GaussDBLockingSupport.setLockTimeout with the sentinel value.","commonSituations":"Optimistic retry loops that use NOWAIT to avoid blocking, ported to GaussDB; a global lock.timeout=0 setting in persistence.xml; code shared between PostgreSQL and GaussDB deployments.","solutions":["Use a small positive timeout (e.g. Timeout.milliseconds(1) or a few ms) to approximate no-wait, or waitForever().","Express NOWAIT through the query's row-level locking options (lock mode / follow-on locking) instead of the connection lock-timeout.","Remove the lock.timeout=0 hint on GaussDB deployments.","Catch HibernateException and retry with a valid timeout."],"exampleFix":"// before - throws on GaussDB\nquery.setLockTimeout(Timeout.noWait());\n\n// after - near-immediate timeout instead of the no-wait sentinel\nquery.setLockTimeout(Timeout.milliseconds(1));","handlingStrategy":"validation","validationCode":"boolean gauss = sessionFactory.getJdbcServices().getDialect() instanceof org.hibernate.community.dialect.GaussDBDialect;\nTimeout t = gauss && requested.isNoWait()\n        ? Timeout.milliseconds(1)   // approximate no-wait with a tiny timeout\n        : requested;","typeGuard":"static boolean usableAsConnectionLockTimeout(Timeout t) {\n    return !t.isSkipLocked() && !t.isNoWait();\n}","tryCatchPattern":"try {\n    query.setLockTimeout(Timeout.noWait()).getResultList();\n} catch (HibernateException e) {\n    if (e.getMessage().contains(\"no-wait\")) {\n        query.setLockTimeout(Timeout.milliseconds(1)).getResultList();\n    } else throw e;\n}","preventionTips":["Avoid lock.timeout=0 hints on GaussDB","Model NOWAIT retry loops with tiny timeouts or dialect-native SQL"],"tags":["gaussdb","locking","pessimistic-lock","lock-timeout","no-wait","hibernate-exception"],"backgroundTag":"unsupported-lock-timeout","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}