baomidou/mybatis-plus · error · IllegalArgumentException
`likeTable` and `notLikeTable` configurations are mutually e
Error message
`likeTable` and `notLikeTable` configurations are mutually exclusive and cannot be used simultaneously.
What it means
StrategyConfig.validate() throws IllegalArgumentException when both likeTable and notLikeTable are set. LIKE-matching and NOT-LIKE-matching table filters are mutually exclusive by design; validate() enforces this before generation starts.
Source
Thrown at mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/StrategyConfig.java:273
* @since 3.3.2
*/
public boolean startsWithTablePrefix(@NotNull String tableName) {
return this.tablePrefix.stream().anyMatch(tableName::startsWith);
}
/**
* 验证配置项
*
* @since 3.5.0
*/
public void validate() {
boolean isInclude = !this.getInclude().isEmpty();
boolean isExclude = !this.getExclude().isEmpty();
if (isInclude && isExclude) {
throw new IllegalArgumentException("`include` and `exclude` configurations are mutually exclusive and cannot be used simultaneously.");
}
if (this.getNotLikeTable() != null && this.getLikeTable() != null) {
throw new IllegalArgumentException("`likeTable` and `notLikeTable` configurations are mutually exclusive and cannot be used simultaneously.");
}
}
/**
* 包含表名匹配
*
* @param tableName 表名
* @return 是否匹配
* @since 3.5.0
*/
public boolean matchIncludeTable(@NotNull String tableName) {
return matchTable(tableName, this.getInclude());
}
/**
* 排除表名匹配
*
* @param tableName 表名View on GitHub (pinned to bf67d90747)
Solutions
- Delete one of the two: keep likeTable for an allow-pattern or notLikeTable for a deny-pattern, never both.
- If you need pattern allow + pattern deny, switch to explicit include/exclude lists computed from DatabaseMetaData# getTables before generation.
- Add an early strategyConfig.validate() call or unit test to surface the conflict at startup.
Example fix
// before
strategy.likeTable(new LikeTable("user"));
strategy.notLikeTable(new LikeTable("tmp")); // conflict
// after
strategy.notLikeTable(new LikeTable("tmp")); // single pattern filter only Defensive patterns
Strategy: validation
Validate before calling
if (strategyConfig.getLikeTable() != null && strategyConfig.getNotLikeTable() != null) {
throw new IllegalArgumentException("choose likeTable OR notLikeTable");
}
strategyConfig.validate(); Prevention
- Use exactly one pattern filter; express anything more complex with include/exclude lists.
- Fail fast by calling validate() in a config unit test.
- When migrating configs, grep for both setters to ensure the old one was removed.
When it happens
Trigger: Configuring StrategyConfig with both .likeTable(new LikeTable("user")) and .notLikeTable(new LikeTable("tmp")) (or setters setLikeTable/setNotLikeTable), then calling generate().
Common situations: Migrating an older config that used likeTable and later adding notLikeTable to skip temp tables, without removing the old setting; chaining fluent builder calls copied from documentation samples that each use a different filter.
Related errors
- `include` and `exclude` configurations are mutually exclusiv
- %s 的名称转换结果为空,请检查是否配置问题
- 读取[%s]字段出错!
- %s already contains value for %s
- %s does not contain value for %s
AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14).
Data as JSON: /api/errors/a3443d6ef017db1e.
Report an issue: GitHub.