Skip to content

Commit 2ee34a5

Browse files
committed
Add MySQLTableMetaDataProvider for correct generated-keys support
Closes gh-35593
1 parent 1bc82d2 commit 2ee34a5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2002-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.jdbc.core.metadata;
18+
19+
import java.sql.DatabaseMetaData;
20+
import java.sql.SQLException;
21+
22+
/**
23+
* The MySQL/MariaDB specific implementation of {@link TableMetaDataProvider}.
24+
* Sets {@link #setGeneratedKeysColumnNameArraySupported} to {@code false}.
25+
*
26+
* @author Juergen Hoeller
27+
* @since 6.2.12
28+
*/
29+
public class MySQLTableMetaDataProvider extends GenericTableMetaDataProvider {
30+
31+
public MySQLTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
32+
super(databaseMetaData);
33+
setGeneratedKeysColumnNameArraySupported(false);
34+
}
35+
36+
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataProviderFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ else if ("Apache Derby".equals(databaseProductName)) {
6666
else if ("HSQL Database Engine".equals(databaseProductName)) {
6767
provider = new HsqlTableMetaDataProvider(databaseMetaData);
6868
}
69+
else if ("MySQL".equals(databaseProductName) || "MariaDB".equals(databaseProductName)) {
70+
provider = new MySQLTableMetaDataProvider(databaseMetaData);
71+
}
6972
else {
7073
provider = new GenericTableMetaDataProvider(databaseMetaData);
7174
}

0 commit comments

Comments
 (0)