{"record":{"id":"c6147b554158ecf8","repo":"MyCATApache/Mycat-Server","slug":"txisolation-txisolation","errorCode":null,"errorMessage":"txIsolation:${txIsolation}","messagePattern":"txIsolation:(.+?)","errorType":"exception","errorClass":"UnknownTxIsolationException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/backend/mysql/nio/MySQLConnection.java","lineNumber":345,"sourceCode":"\t\t\t\t.append(\";\");\n\t}\n\n\tprivate static void getTxIsolationCommand(StringBuilder sb, int txIsolation) {\n\t\tswitch (txIsolation) {\n\t\tcase Isolations.READ_UNCOMMITTED:\n\t\t\tsb.append(\"SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;\");\n\t\t\treturn;\n\t\tcase Isolations.READ_COMMITTED:\n\t\t\tsb.append(\"SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;\");\n\t\t\treturn;\n\t\tcase Isolations.REPEATED_READ:\n\t\t\tsb.append(\"SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;\");\n\t\t\treturn;\n\t\tcase Isolations.SERIALIZABLE:\n\t\t\tsb.append(\"SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;\");\n\t\t\treturn;\n\t\tdefault:\n\t\t\tthrow new UnknownTxIsolationException(\"txIsolation:\" + txIsolation);\n\t\t}\n\t}\n\n\tprivate void getAutocommitCommand(StringBuilder sb, boolean autoCommit) {\n\t\tif (autoCommit) {\n\t\t\tsb.append(\"SET autocommit=1;\");\n\t\t} else {\n\t\t\tsb.append(\"SET autocommit=0;\");\n\t\t}\n\t}\n\tprivate void getTxReadonly(StringBuilder sb, boolean txReadonly) {\n\t\tif (txReadonly) {\n\t\t\tsb.append(\"SET SESSION TRANSACTION READ ONLY;\");\n\t\t} else {\n\t\t\tsb.append(\"SET SESSION TRANSACTION READ WRITE;\");\n\t\t}\n\t}\n\tprivate void getSqlSelectLimit(StringBuilder sb, int sqlSelectLimit) {","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/mysql/nio/MySQLConnection.java#L327-L363","documentation":"MySQLConnection.getTxIsolationCommand throws UnknownTxIsolationException with message 'txIsolation:<value>' when building the SET SESSION TRANSACTION ISOLATION LEVEL statement for a transaction-isolation constant it does not recognize. Only the known Mycat Isolations constants (READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE) map to SQL; anything else reaches the default branch.","triggerScenarios":"A datasource/transaction configuration sets txIsolation to an out-of-range or unknown integer, then synAndDoExecute prepares to send the connection to MySQL.","commonSituations":"Typo'd or hand-edited schema.xml/server.xml txIsolation values; custom code passing raw integers instead of the Isolations constants; config migrated from another product with different enum numbering.","solutions":["Set txIsolation to a valid Mycat Isolations value (1=READ_UNCOMMITTED, 2=READ_COMMITTED, 3=REPEATABLE_READ, 4=SERIALIZABLE) in the datasource config","Check the message's txIsolation:<n> value and map it against io.mycat.backend.mysql.Isolations before deploying","Add a startup validation step that rejects unknown isolation values early instead of at connection time"],"exampleFix":"// before (schema.xml)\n<dsNode ... txIsolation=\"5\" />\n// after\n<dsNode ... txIsolation=\"3\" /> <!-- REPEATABLE_READ -->","handlingStrategy":"validation","validationCode":"int tx = cfg.getTxIsolation();\nif (tx < 1 || tx > 4) throw new IllegalArgumentException(\"txIsolation must be 1-4 (Isolations constants), got \" + tx);","typeGuard":"boolean isValidTxIsolation(int v){ return v >= 1 && v <= 4; } // matches Isolations.READ_UNCOMMITTED..SERIALIZABLE","tryCatchPattern":"try { conn.synAndDoExecute(...); } catch (UnknownTxIsolationException e) { log.error(\"Invalid txIsolation in datasource config: {}\", e.getMessage()); throw new ConfigException(e); }","preventionTips":["Always set txIsolation using named Isolations constants, not raw numbers","Validate schema.xml/server.xml values at startup with a config linter","Never copy txIsolation numeric values from other products with different enum orderings"],"tags":["mysql","transaction-isolation","config"],"backgroundTag":"invalid-enum-value","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}