Remove custom Hibernate dialect detection

Closes #27954

Signed-off-by: synth3 <19573241+synth3@users.noreply.github.com>
This commit is contained in:
synth3 2024-03-15 19:29:58 +01:00 committed by Alexander Schwartz
parent 32541f19a3
commit 99478887a4

View file

@ -210,8 +210,9 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
try { try {
prepareOperationalInfo(connection); prepareOperationalInfo(connection);
String driverDialect = detectDialect(connection); String driverDialect = config.get("driverDialect");
if (driverDialect != null) { // use configured dialect, else rely on Hibernate detection
if (driverDialect != null && !driverDialect.isBlank()) {
properties.put("hibernate.dialect", driverDialect); properties.put("hibernate.dialect", driverDialect);
} }
@ -289,47 +290,6 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide
} }
} }
protected String detectDialect(Connection connection) {
String driverDialect = config.get("driverDialect");
if (driverDialect != null && driverDialect.length() > 0) {
return driverDialect;
} else {
try {
String dbProductName = connection.getMetaData().getDatabaseProductName();
String dbProductVersion = connection.getMetaData().getDatabaseProductVersion();
// For MSSQL2014, we may need to fix the autodetected dialect by hibernate
if (dbProductName.equals("Microsoft SQL Server")) {
String topVersionStr = dbProductVersion.split("\\.")[0];
boolean shouldSet2012Dialect = true;
try {
int topVersion = Integer.parseInt(topVersionStr);
if (topVersion < 12) {
shouldSet2012Dialect = false;
}
} catch (NumberFormatException nfe) {
}
if (shouldSet2012Dialect) {
String sql2012Dialect = "org.hibernate.dialect.SQLServer2012Dialect";
logger.debugf("Manually override hibernate dialect to %s", sql2012Dialect);
return sql2012Dialect;
}
}
// For Oracle19c, we may need to set dialect explicitly to workaround https://hibernate.atlassian.net/browse/HHH-13184
if (dbProductName.equals("Oracle") && connection.getMetaData().getDatabaseMajorVersion() > 12) {
logger.debugf("Manually specify dialect for Oracle to org.hibernate.dialect.Oracle12cDialect");
return "org.hibernate.dialect.Oracle12cDialect";
}
} catch (SQLException e) {
logger.warnf("Unable to detect hibernate dialect due database exception : %s", e.getMessage());
}
return null;
}
}
protected void startGlobalStats(KeycloakSession session, int globalStatsIntervalSecs) { protected void startGlobalStats(KeycloakSession session, int globalStatsIntervalSecs) {
logger.debugf("Started Hibernate statistics with the interval %s seconds", globalStatsIntervalSecs); logger.debugf("Started Hibernate statistics with the interval %s seconds", globalStatsIntervalSecs);
TimerProvider timer = session.getProvider(TimerProvider.class); TimerProvider timer = session.getProvider(TimerProvider.class);