{"record":{"id":"a1ce0edc7f082d58","repo":"tursodatabase/turso","slug":"invalid-transaction-isolation-level-level","errorCode":null,"errorMessage":"Invalid transaction isolation level: {level}","messagePattern":"Invalid transaction isolation level: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"bindings/java/src/main/java/tech/turso/core/TursoConnection.java","lineNumber":301,"sourceCode":"   *     Connection.TRANSACTION_READ_UNCOMMITTED}, {@code Connection.TRANSACTION_READ_COMMITTED},\n   *     {@code Connection.TRANSACTION_REPEATABLE_READ}, or {@code\n   *     Connection.TRANSACTION_SERIALIZABLE}.\n   * @throws SQLException if a database access error occurs, this method is called on a closed\n   *     connection or the given parameter is not one of the {@code Connection} constants\n   */\n  public void setTransactionIsolation(int level) throws SQLException {\n    synchronized (transactionLock) {\n      checkOpen();\n\n      if (inTransaction) {\n        throw new SQLException(\"Cannot change isolation level while transaction is active.\");\n      }\n\n      if (level != Connection.TRANSACTION_READ_UNCOMMITTED\n          && level != Connection.TRANSACTION_READ_COMMITTED\n          && level != Connection.TRANSACTION_REPEATABLE_READ\n          && level != Connection.TRANSACTION_SERIALIZABLE) {\n        throw new SQLException(\"Invalid transaction isolation level: \" + level);\n      }\n\n      this.transactionIsolation = level;\n    }\n  }\n\n  /**\n   * Retrieves the current transaction isolation level.\n   *\n   * @return the current transaction isolation level\n   * @throws SQLException if a database access error occurs or the connection is closed\n   */\n  public int getTransactionIsolation() throws SQLException {\n    checkOpen();\n    return transactionIsolation;\n  }\n\n  /**","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/java/src/main/java/tech/turso/core/TursoConnection.java#L283-L319","documentation":"Thrown by TursoConnection.setTransactionIsolation(int) when level is not one of the four accepted JDBC constants: TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, or TRANSACTION_SERIALIZABLE. The setter stores the level verbatim, so it validates the full domain up front under the transaction lock. Note that TRANSACTION_NONE (0), a standard JDBC constant, is rejected because the engine cannot disable isolation.","triggerScenarios":"Calling conn.setTransactionIsolation(level) with Connection.TRANSACTION_NONE, an arbitrary int (e.g. 5 or -1), or a value read from configuration that is not exactly one of the four accepted constants. Calling it while a transaction is active throws a different message first ('Cannot change isolation level while transaction is active.').","commonSituations":"Ported JDBC code that defaults to TRANSACTION_NONE; passing a connection-pool property (e.g. HikariCP's transactionIsolation) straight through as an int; constants renamed or mistyped after a refactor; code written for PostgreSQL/MySQL where NONE is accepted.","solutions":["Pass exactly one of the four Connection constants listed in the check","If you meant TRANSACTION_NONE, remove the call entirely: the engine has no dirty reads and the connection default is already fine","Map free-form config strings/values to the four constants through an allowlist before calling the setter","As a last resort, wrap the call in try-catch and fall back to the value returned by getTransactionIsolation()"],"exampleFix":"// before\nconn.setTransactionIsolation(Connection.TRANSACTION_NONE); // throws\n\n// after\n// TRANSACTION_NONE is not supported; only these four are accepted\nconn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);","handlingStrategy":"validation","validationCode":"private static final Set<Integer> SUPPORTED_ISOLATION = Set.of(\n    Connection.TRANSACTION_READ_UNCOMMITTED,\n    Connection.TRANSACTION_READ_COMMITTED,\n    Connection.TRANSACTION_REPEATABLE_READ,\n    Connection.TRANSACTION_SERIALIZABLE);\n\nif (!SUPPORTED_ISOLATION.contains(level)) {\n  throw new IllegalArgumentException(\n      \"level must be one of the four JDBC isolation constants, got: \" + level);\n}\nconn.setTransactionIsolation(level);","typeGuard":null,"tryCatchPattern":"try {\n  conn.setTransactionIsolation(level);\n} catch (SQLException e) {\n  // keep the current level; surface a clear config error instead of a generic SQLException\n  throw new ConfigurationException(\"unsupported isolation level: \" + level, e);\n}","preventionTips":["Map pool/config strings to the four constants through one allowlist function","Set isolation once at connection setup, never inside an active transaction","Unit-test every configurable level value against the allowlist"],"tags":["java","jdbc","transaction","isolation-level","invalid-argument"],"backgroundTag":"invalid-transaction-isolation-level","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}