{"record":{"id":"1874cfe3d7959818","repo":"mybatis/mybatis-3","slug":"unknown-statement-type","errorCode":null,"errorMessage":"Unknown statement type: {}","messagePattern":"Unknown statement type: (.+?)","errorType":"validation","errorClass":"ExecutorException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/executor/statement/RoutingStatementHandler.java","lineNumber":53,"sourceCode":"public class RoutingStatementHandler implements StatementHandler {\n\n  private final StatementHandler delegate;\n\n  public RoutingStatementHandler(Executor executor, MappedStatement ms, Object parameter, RowBounds rowBounds,\n      ResultHandler resultHandler, BoundSql boundSql) {\n\n    switch (ms.getStatementType()) {\n      case STATEMENT:\n        delegate = new SimpleStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);\n        break;\n      case PREPARED:\n        delegate = new PreparedStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);\n        break;\n      case CALLABLE:\n        delegate = new CallableStatementHandler(executor, ms, parameter, rowBounds, resultHandler, boundSql);\n        break;\n      default:\n        throw new ExecutorException(\"Unknown statement type: \" + ms.getStatementType());\n    }\n\n  }\n\n  @Override\n  public Statement prepare(Connection connection, Integer transactionTimeout) throws SQLException {\n    return delegate.prepare(connection, transactionTimeout);\n  }\n\n  @Override\n  public void parameterize(Statement statement) throws SQLException {\n    delegate.parameterize(statement);\n  }\n\n  @Override\n  public void batch(Statement statement) throws SQLException {\n    delegate.batch(statement);\n  }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/executor/statement/RoutingStatementHandler.java#L35-L71","documentation":"RoutingStatementHandler switches on mappedStatement.getStatementType() and knows only STATEMENT, PREPARED, and CALLABLE. Any other value falls through to 'Unknown statement type'. With the stock StatementType enum this is defensive dead code; in practice it appears when a custom/modified enum, a different MyBatis fork, or a corrupted serialization of MappedStatement introduces an unexpected value.","triggerScenarios":"Constructing a RoutingStatementHandler for a MappedStatement whose statementType is not one of the three known enum constants — e.g. custom StatementType extension, MappedStatement deserialized from an incompatible version, or shaded/duplicated mybatis jars with diverging enums.","commonSituations":"Mixing MyBatis versions on the classpath (mybatis + mybatis-spring or mybatis-plus pulling different versions); caching/serializing MappedStatement across versions; custom source forks adding a new statement type without updating RoutingStatementHandler.","solutions":["Align all MyBatis artifacts to one version (check mvn dependency:tree for mybatis* artifacts).","Remove duplicate/forked mybatis jars from the classpath so a single StatementType enum is used.","If you maintain a fork adding a statement type, extend RoutingStatementHandler's switch accordingly.","Do not cache or transport MappedStatement objects across different MyBatis versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// startup check: exactly one mybatis core on the classpath\nEnumeration<URL> jars = getClass().getClassLoader().getResources(\"org/apache/ibatis/session/Configuration.class\");\nList<URL> found = Collections.list(jars);\nif (found.size() != 1) {\n  throw new IllegalStateException(\"Multiple/split mybatis classes found: \" + found);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use Maven enforcer (bannedDependencies/duplicateClasses) or Gradle version alignment to keep one mybatis artifact.","Never pass MappedStatement objects between processes or versions."],"tags":["mybatis","statement-type","classpath","internal"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}