Description
多张表分库,表名大写找不到表,只有其中一张表能查询,其他不能查询。
spring boot 1.5.9 mybatis3.4.5 shardingjdbc 2.0.1
其中一张表能查到数据,其他的表都报找不到表。表名都是大写 t1表无法查询,报错
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: io.shardingjdbc.core.exception.ShardingJdbcException: io.shardingjdbc.core.exception.ShardingJdbcException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xx.T1' doesn't exist
The error may exist in file [T1Mapper.xml]
The error may involve defaultParameterMap
The error occurred while setting parameters
SQL: SELECT * from T1
Cause: io.shardingjdbc.core.exception.ShardingJdbcException: io.shardingjdbc.core.exception.ShardingJdbcException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'xx.T1' doesn't exist
T2表查询没有问题
private Map<String, DataSource> createDataSourceMap() {
HashMap<String, DataSource> dataSourceMap = new HashMap<>();
for (Map<String, String> database : myProps.getDatabase()) {
HikariDataSource ds = (HikariDataSource) DataSourceBuilder.create()
.url(database.get("url"))
.username(database.get("username"))
.password(database.get("password"))
.driverClassName(database.get("driveClassName"))
.type(HikariDataSource.class).build();
ds.setConnectionTestQuery("SELECT 1");
dataSourceMap.put(database.get("name"), ds);
}
return dataSourceMap;
}
@Bean
@Primary
public DataSource shardingDataSource() throws SQLException {
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTableRuleConfigs().add(getT1TableRuleConfiguration());
shardingRuleConfig.getTableRuleConfigs().add(getT2TableRuleConfiguration());
shardingRuleConfig.getBindingTableGroups().add("T1, T2");
shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("T1", PreciseModuloDatabaseShardingAlgorithm.class.getName()));
return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, new HashMap<String, Object>(), new Properties());
}
private TableRuleConfiguration getT1TableRuleConfiguration() {
TableRuleConfiguration retailOrderTableRuleConfig = new TableRuleConfiguration();
retailOrderTableRuleConfig.setLogicTable("T1");
return retailOrderTableRuleConfig;
}
private TableRuleConfiguration getT2TableRuleConfiguration() {
TableRuleConfiguration retailOrderTableRuleConfig = new TableRuleConfiguration();
retailOrderTableRuleConfig.setLogicTable("T2");
return retailOrderTableRuleConfig;
}