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.
Comment From: zrlw
we fix it by calling setDataSource(dataSource) again at the beginning of doTranslate() of SQLErrorCodeSQLExceptionTranslator.
Comment From: zrlw
same with #25681