{"record":{"id":"22e514a86e1e628a","repo":"MyCATApache/Mycat-Server","slug":"batch-not-supported","errorCode":null,"errorMessage":"batch not supported","messagePattern":"batch not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/backend/jdbc/mongodb/MongoStatement.java","lineNumber":216,"sourceCode":"\t\treturn this._fetchSize;\n\t}\n\n\t@Override\n\tpublic int getResultSetConcurrency() throws SQLException {\n\t\t// 对象生成的 ResultSet 对象的结果集合并发性\n\t\treturn 0;\n\t}\n\n\t@Override\n\tpublic int getResultSetType() throws SQLException {\n\t\t// 对象生成的 ResultSet 对象的结果集合类型。\n\t\treturn 0;\n\t}\n\n\t@Override\n\tpublic void addBatch(String sql) throws SQLException {\n\t\t// 新增批处理\n\t   throw new UnsupportedOperationException(\"batch not supported\");\n\t}\n\n\t@Override\n\tpublic void clearBatch() throws SQLException {\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic int[] executeBatch() throws SQLException {\n\t\t// 将一批命令提交给数据库来执行，如果全部命令执行成功，则返回更新计数组成的数组。\n\t\tthrow new UnsupportedOperationException();\n\t}\n\n\t@Override\n\tpublic Connection getConnection() throws SQLException {\n\t\t\n\t\treturn this._conn;\n\t}","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/backend/jdbc/mongodb/MongoStatement.java#L198-L234","documentation":"MongoStatement.addBatch(String) explicitly throws UnsupportedOperationException with the message 'batch not supported'. The MongoDB backend of Mycat does not implement JDBC batch execution, so any attempt to queue a statement into a batch fails immediately.","triggerScenarios":"Calling addBatch(String sql) on a statement obtained from the MongoDB backend driver; using code paths that buffer SQL statements before executeBatch().","commonSituations":"Bulk-insert code written for MySQL/PostgreSQL reused against the MongoDB driver; ORMs or ETL tools that call addBatch automatically during bulk operations.","solutions":["Refactor the caller to execute each SQL statement individually with executeUpdate()/execute() in a loop instead of batching.","Wrap batch-queuing logic in a capability check so the MongoDB backend uses per-statement execution.","Remove addBatch usage from ORM/tooling configuration for this driver (e.g. disable JDBC batching in Hibernate: hibernate.jdbc.batch_size=0).","Patch MongoStatement to implement batching by accumulating SQL and issuing multi-document writes to MongoDB.","Use a different backend/driver if true server-side batching is required."],"exampleFix":"// before\nstmt.addBatch(\"INSERT INTO t VALUES (1)\");\nstmt.addBatch(\"INSERT INTO t VALUES (2)\");\nstmt.executeBatch();\n// after\nstmt.executeUpdate(\"INSERT INTO t VALUES (1)\");\nstmt.executeUpdate(\"INSERT INTO t VALUES (2)\");","handlingStrategy":"try-catch","validationCode":"// check backend before batching\nDatabaseMetaData md = conn.getMetaData();\nboolean batchSupported;\ntry { md.supportsBatchUpdates(); batchSupported = true; }\ncatch (SQLException e) { batchSupported = false; }\nif (!batchSupported) { executeIndividually(conn, sqlList); return; }","typeGuard":"boolean isMongoBackend(Connection c) {\n    try { return c.getMetaData().getDatabaseProductName().toLowerCase().contains(\"mongo\"); }\n    catch (SQLException e) { return false; }\n}","tryCatchPattern":"try {\n    stmt.addBatch(sql);\n} catch (UnsupportedOperationException e) {\n    stmt.executeUpdate(sql); // fall back to single-statement execution\n}","preventionTips":["Prefer loops of executeUpdate() over addBatch/executeBatch when the driver is the Mycat MongoDB backend.","Disable JDBC batching in ORM settings for this driver.","Centralize batch logic behind an abstraction that checks driver batch support."],"tags":["jdbc","mongodb","batch","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}