### Error querying database. Cause: java.lang.RuntimeException: 无法处理该类型[class com.github.pagehelper.sqlsource.PageDynamicSqlSource]的SqlSource
### Cause: java.lang.RuntimeException: 无法处理该类型[class com.github.pagehelper.sqlsource.PageDynamicSqlSource]的SqlSource
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:79)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
at com.sun.proxy.$Proxy72.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:231)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:128)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53
使用版本:4.1.6 说明:查看5.0.1版本源码,该部分代码没变,应该也可以重现该bug 异常现场:
重现: 在启一个线程池,进行同一个分页查询操作时,出现RuntimeException,无法处理该类型PageDynamicSqlSource
所用代码如下:
异常分析: 在SqlUtils方法中有以下处理:
其中: processMappedStatement方法为:
由于processMappedStatement是非线程安全的方法,虽然前面进行过if判断,进入这个方法体后sqlSource对象还是有可能是处理过的PageSqlSource,此时instanceof 判断失败,抛出RuntimeException
建议订正: 在条件判断最后,再进行一次PageSqlSource的判断,如果是,直接返回: