{"record":{"id":"f33ed0309456684b","repo":"hibernate/hibernate-orm","slug":"lock-timeout-on-the-jdbc-connection-is-not-support","errorCode":null,"errorMessage":"Lock timeout on the JDBC connection is not supported","messagePattern":"Lock timeout on the JDBC connection is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/lock/spi/ConnectionLockTimeoutStrategy.java","lineNumber":40,"sourceCode":"\tConnectionLockTimeoutStrategy NONE = () -> Level.NONE;\n\n\t/**\n\t * What type, if any, of support this Dialect has for lock timeouts on the JDBC connection.\n\t *\n\t * @see #getLockTimeout\n\t * @see #setLockTimeout\n\t */\n\tLevel getSupportedLevel();\n\n\t/**\n\t * Read the lock timeout associated with the JDBC connection, if supported and there is one.\n\t *\n\t * @see #getSupportedLevel\n\t *\n\t * @throws UnsupportedOperationException when {@linkplain #getSupportedLevel} is {@linkplain Level#NONE}\n\t */\n\tdefault Timeout getLockTimeout(Connection connection, SessionFactoryImplementor factory) {\n\t\tthrow new UnsupportedOperationException( \"Lock timeout on the JDBC connection is not supported\" );\n\t}\n\n\t/**\n\t * Set the lock timeout associated with the JDBC connection (if supported), in milliseconds.\n\t *\n\t * @see #getSupportedLevel()\n\t *\n\t * @throws UnsupportedOperationException when {@linkplain #getSupportedLevel} is {@linkplain Level#NONE}\n\t */\n\tdefault void setLockTimeout(Timeout timeout, Connection connection, SessionFactoryImplementor factory) {\n\t\tthrow new UnsupportedOperationException( \"Lock timeout on the JDBC connection is not supported\" );\n\t}\n\n\t/**\n\t * Indicates a Dialect's level of support for lock timeouts on the JDBC connection.\n\t *\n\t * @apiNote {@linkplain org.hibernate.Timeouts#SKIP_LOCKED skip-locked} is never supported.\n\t */","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/lock/spi/ConnectionLockTimeoutStrategy.java#L22-L58","documentation":"ConnectionLockTimeoutStrategy is the Hibernate 7 SPI for connection-level lock timeouts; dialects that cannot do it (H2, HSQLDB, Oracle, HANA, TimesTen, Spanner, default LockingSupport) return Level.NONE and keep the base default methods, which throw UnsupportedOperationException. This instance means getLockTimeout(...) was called on such a NONE-level strategy - the standard pipeline only wires LockTimeoutHandler when the dialect itself declared CONNECTION timeout support, so in practice this is hit by custom code or custom dialect integrations calling the SPI without checking the level first.","triggerScenarios":"Directly invoking sessionFactory.getJdbcServices().getDialect().getLockingSupport().getConnectionLockTimeoutStrategy().getLockTimeout(connection, factory) on a NONE-level dialect (H2, Oracle, HANA, Spanner, ...); a custom Dialect overriding getLockingSupport() or a copied LockTimeoutHandler without the getSupportedLevel() guard; custom O/RM tooling built on the Hibernate SPI assuming every dialect supports connection timeouts.","commonSituations":"Custom dialects (in-house databases, test dialects) left with ConnectionLockTimeoutStrategy.NONE; framework/utility code written against one database and reused on another; upgrading to Hibernate 7 where this incubating SPI appeared and internal code was refactored onto it.","solutions":["Always check getSupportedLevel() != Level.NONE before calling getLockTimeout/setLockTimeout","For custom dialects of databases with a session lock timeout command, implement ConnectionLockTimeoutStrategy (see PostgreSQLLockingSupport as a template) instead of leaving NONE","If capability detection must be defensive, catch UnsupportedOperationException explicitly"],"exampleFix":"// before\nTimeout baseline = strategy.getLockTimeout(connection, factory); // throws on Level.NONE\n\n// after\nif (strategy.getSupportedLevel() == ConnectionLockTimeoutStrategy.Level.NONE) {\n    // fall back: no connection-level lock timeout available\n} else {\n    Timeout baseline = strategy.getLockTimeout(connection, factory);\n}","handlingStrategy":"validation","validationCode":"if (strategy.getSupportedLevel() == ConnectionLockTimeoutStrategy.Level.NONE) {\n    // do not call getLockTimeout: this dialect has no connection-level lock timeout\n} else {\n    Timeout baseline = strategy.getLockTimeout(connection, factory);\n}","typeGuard":"static boolean supportsConnectionLockTimeout(ConnectionLockTimeoutStrategy s) {\n    return s.getSupportedLevel() != ConnectionLockTimeoutStrategy.Level.NONE;\n}","tryCatchPattern":"try {\n    Timeout baseline = strategy.getLockTimeout(connection, factory);\n} catch (UnsupportedOperationException e) {\n    // Level.NONE dialect: skip connection-level timeout handling\n}","preventionTips":["Always branch on getSupportedLevel() before using the ConnectionLockTimeoutStrategy SPI","For custom dialects, implement the strategy if the database has a session lock-timeout command","Do not assume every dialect supports connection-level lock timeouts (Oracle, H2, HANA, Spanner do not)","Unit-test custom locking plumbing against a NONE-level dialect"],"tags":["dialect","lock-timeout","unsupported-operation","spi","hibernate"],"backgroundTag":"connection-lock-timeout-unsupported","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}