baomidou/mybatis-plus · error · MybatisPlusException

Table name processing failed :

Error message

Table name processing failed : 

What it means

Thrown by DynamicTableNameJsqlParserInnerInterceptor when table-name rewriting fails at both layers: JSqlParser could not process the SQL (or produced an UnsupportedStatement whose fallback also failed), the parent DynamicTableNameInnerInterceptor regex/AST-based processing threw, and ignoreException is false (default). It wraps the last underlying exception, so the real cause (usually a JSQLParser parse error) is in the cause chain.

Source

Thrown at mybatis-plus-jsqlparser-support/mybatis-plus-jsqlparser/src/main/java/com/baomidou/mybatisplus/extension/plugins/inner/DynamicTableNameJsqlParserInnerInterceptor.java:86

            return statement.toString();
        } catch (Exception exception) {
            return handleFallback(unsupported, sql, exception);
        }
    }

    private String handleFallback(boolean unsupported, String sql, Exception originalException) {
        Exception exception = originalException;
        if (!unsupported || shouldFallback) {
            try {
                return super.processTableName(sql);
            } catch (Exception e) {
                exception = e;
            }
        }
        if (ignoreException) {
            return sql;
        }
        throw new MybatisPlusException("Table name processing failed : ", exception);
    }

}

View on GitHub (pinned to bf67d90747)

Solutions

  1. Inspect the wrapped cause (e.getCause()) to find the exact JSqlParser error position and fix the SQL syntax
  2. Set ignoreException=true on the interceptor so unparseable SQL passes through unrewritten (accepting that the table name is not replaced for that statement)
  3. Since shouldFallback defaults to true, verify the failure is a genuine parse error in the parent too; if the parent's TableNameParser fails on a false positive, simplify the SQL
  4. Extract vendor-specific statements out of the intercepted mapper so the interceptor never sees them

Example fix

// before
DynamicTableNameJsqlParserInnerInterceptor interceptor = new DynamicTableNameJsqlParserInnerInterceptor(handler);
// after (tolerate unparseable SQL, skip rewriting for it)
DynamicTableNameJsqlParserInnerInterceptor interceptor = new DynamicTableNameJsqlParserInnerInterceptor(handler);
interceptor.setIgnoreException(true);
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-parse SQL before it reaches the dynamic-table-name interceptor
try {
    Statement st = JsqlParserGlobal.parse(sql);
    if (st instanceof UnsupportedStatement) {
        LOGGER.warn("SQL unsupported by JSqlParser, will fall through: {}", sql);
    }
} catch (Exception e) {
    throw new IllegalArgumentException("SQL unparseable by JSqlParser: " + sql, e);
}

Type guard

static boolean isParseableByJsqlParser(String sql) {
    try { JsqlParserGlobal.parse(sql); return true; }
    catch (Exception e) { return false; }
}

Try / catch

try {
    return mapper.insertSpecialDialectSql(entity);
} catch (MybatisPlusException e) {
    if ("Table name processing failed : ".equals(e.getMessage())) {
        // either route around the interceptor or log & set ignoreException=true
        LOGGER.error("Dynamic table name rewrite failed", e.getCause());
        throw e;
    }
    throw e;
}

Prevention

When it happens

Trigger: Executing SQL that JSqlParser cannot parse (vendor-specific syntax like clickhouse/pg extensions, malformed SQL) or an UnsupportedStatement while a DynamicTableNameJsqlParserInnerInterceptor is in the interceptor chain, with default settings (shouldFallback=true already tried, ignoreException=false).

Common situations: Dialect-specific SQL (e.g. PostgreSQL 'RETURNING', MySQL hints, stored procedure calls) routed through dynamic table name rewriting; after upgrading mybatis-plus/jsqlparser where previously-parsed syntax now fails; custom SQL built by string concatenation that is not valid SQL.

Related errors


AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14). Data as JSON: /api/errors/ef64d6f0cfaa9680. Report an issue: GitHub.