Skip to content
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

sharding-jdbc-raw-jdbc-java-example getMetaData() 再 setAutoCommit(false) 无法对之后创建的 realconnection 生效 #472

Closed
liuxiaozhu opened this issue Nov 24, 2017 · 2 comments

Comments

@liuxiaozhu
Copy link

Sharding-jdbc 2.0.0.M3
example master 分支
为复现此情况,修改 sharding-jdbc-raw-jdbc-java-example 中的 RawJdbcRepository 的 execute() 方法:

Connection conn = dataSource.getConnection();

conn.getMetaData();

conn.setAutoCommit(false);

Statement statement = conn.createStatement();
statement.execute(sql);
conn.commit();

statement.close();
conn.close();

getMetaData() 时获取了一个 realconnection 存入了 AbstractConnectionAdapter 的 cachedConnections 中,导致之后的
cachedConnections 中一个连接是 autocommit = true 另一个 autocommit = false 在 commit 时,报错了:

Exception in thread "main" java.sql.SQLException
	at io.shardingjdbc.core.jdbc.adapter.WrapperAdapter.throwSQLExceptionIfNecessary(WrapperAdapter.java:82)
	at io.shardingjdbc.core.jdbc.adapter.AbstractConnectionAdapter.commit(AbstractConnectionAdapter.java:77)
	at io.shardingjdbc.example.jdbc.java.repository.RawJdbcRepository.execute(RawJdbcRepository.java:109)
	at io.shardingjdbc.example.jdbc.java.repository.RawJdbcRepository.createTable(RawJdbcRepository.java:33)
	at io.shardingjdbc.example.jdbc.java.repository.RawJdbcRepository.demo(RawJdbcRepository.java:21)
	at io.shardingjdbc.example.jdbc.java.RawJdbcJavaShardingDatabaseAndTableMain.main(RawJdbcJavaShardingDatabaseAndTableMain.java:40)
@terrymanu
Copy link
Member

多谢能找到隐藏这么深的bug。
fixed at 2.0.0.M4

@terrymanu terrymanu self-assigned this Aug 8, 2018
@Ah39
Copy link

Ah39 commented Aug 24, 2018

ShardingConnection getMetaData 3.0.0.M2 版本还是会去获取连接。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
@liuxiaozhu @Ah39 @terrymanu and others