-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5.0.1版本PageHelper导致ShardingJdbc强制分页失效 #384
Comments
可以配置是否关闭 conn |
谢谢回答,我想是可以通过 properties.put("closeConn","false") 来防止关闭连接,但是会不会造成连接不能释放的问题呢? |
我想通过 |
解决了吗? |
新版本还可以自定义获取dialect实现 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
配置:
PageInterceptor pageInterceptor = new PageInterceptor();
Properties properties = new Properties();
properties.setProperty("autoRuntimeDialect", "true");
pageInterceptor.setProperties(properties);
List mybatisInterceptors = new ArrayList<>();
mybatisInterceptors.add(pageInterceptor);
代码调用:
HintManager hintManager = HintManager.getInstance();
hintManager.addDatabaseShardingValue("project", "id", 2);
hintManager.addTableShardingValue("project", "id", 2);
PageHelper.startPage(0, 2, false);
List projectServices = projectMapper.queryAllProjects();
执行结果异常:报表”product1.product_0001"表不存在
跟踪代码显示ShardingJdbc调用时HintManager中设置的强制分片无效,跟踪PageHelper的代码,发现PageAutoDialect中会在初始dialect时调用getUrl这个方法:
private String getUrl(DataSource dataSource) {
Connection conn = null;
try {
conn = dataSource.getConnection();
return conn.getMetaData().getURL();
} catch (SQLException e) {
throw new PageException(e);
} finally {
if (conn != null) {
try {
if (closeConn) {
conn.close();
}
} catch (SQLException e) {
//ignore
}
}
}
}
这个方法在获取连接,拿到元数据后关闭,问题就在于如果是ShardingJdbc数据源,拿到的连接是ShardingConnection,ShardingJDBC在close连接时,会清除当前线程里的TheadLocal变量,这就导致当前线程设置的强制分片设置丢失了。
能否在getUrl时用新开线程(如Callable)的方式实现,不要对当前线程造成影响?
The text was updated successfully, but these errors were encountered: