diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java index de9d44f1..f6ecf532 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/mybatis/MapperInvocationHandler.java @@ -25,6 +25,7 @@ import com.mybatisflex.core.row.RowMapper; import com.mybatisflex.core.table.TableInfo; import com.mybatisflex.core.table.TableInfoFactory; import com.mybatisflex.core.util.StringUtil; +import org.apache.ibatis.reflection.ExceptionUtil; import javax.sql.DataSource; import java.lang.reflect.InvocationHandler; @@ -76,25 +77,32 @@ public class MapperInvocationHandler implements InvocationHandler { //优先获取用户自己配置的 dbType DbType dbType = DialectFactory.getHintDbType(); - DbType dbTypeGlobal = DialectFactory.getGlobalDbType(); - //当前线程没有设置dbType,但是全局设置了dbTypeGlobal,那么就使用全局的dbTypeGlobal - if(dbTypeGlobal!=null&&dbType==null){ - dbType = dbTypeGlobal ; - } + if (dbType == null) { if (shardingDataSourceKey != null && dataSource != null) { //使用最终分片获取数据源类型 dbType = dataSource.getDbType(shardingDataSourceKey); } + + if (dbType == null && dataSourceKey != null && dataSource != null) { + dbType = dataSource.getDbType(dataSourceKey); + } + + //设置了dbTypeGlobal,那么就使用全局的dbTypeGlobal + if (dbType == null) { + dbType = DialectFactory.getGlobalDbType(); + } + if (dbType == null) { dbType = FlexGlobalConfig.getDefaultConfig().getDbType(); } + DialectFactory.setHintDbType(dbType); needClearDbType = true; } return method.invoke(mapper, args); - } catch (InvocationTargetException e) { - throw e.getCause(); + } catch (Throwable e) { + throw ExceptionUtil.unwrapThrowable(e); } finally { if (needClearDbType) { DialectFactory.clearHintDbType();