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

Can't translate sql errorcode if throws MetaDataAccessException at building SQLErrorCodeSQLExceptionTranslator with DataSource parameter #26930

Closed
zrlw opened this issue May 11, 2021 · 2 comments

Comments

@zrlw
Copy link

zrlw commented May 11, 2021

Affects: \5.2.5.RELEASE(spring-jdbc)

mysql-connector-java: 8.0.19
mybatis-spring-boot-starter: 2.1.2
spring-boot-starter-jdbc: 2.2.6.RELEASE

step 1: set mysql to read only
$ mysql -uroot -p
mysql> set global read_only=ON;
mysql> flush tables with read lock;

step 2: write a test application which inserts a record into the test table.
SQLErrorCodeSQLExceptionTranslator object will be built with datasource input parameter, MetaDataAccessException will be triggered at JdbcUtils.extractDatabaseMetaData call, and a new SQLErrorCodes() will be built as the sqlErrorCodes of the SQLErrorCodeSQLExceptionTranslator object.

step 3: set mysql to read/write
$ mysql -uroot -p
mysql> set global read_only=OFF;
mysql> unlock tables;

step4: continue the test application to insert two same records into the test table which has unique key.
the SQLErrorCodeSQLExceptionTranslator object could not do anything but return null because it;s sqlErrorCodes has empty duplicateKeyCodes.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 11, 2021
@zrlw
Copy link
Author

zrlw commented Jun 22, 2021

we fix it by calling setDataSource(dataSource) again at the beginning of doTranslate() of SQLErrorCodeSQLExceptionTranslator.

@zrlw
Copy link
Author

zrlw commented Jul 10, 2021

same with #25681

@zrlw zrlw closed this as completed Jul 10, 2021
@bclozel bclozel removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants