From 99478887a47796ecd65ae7347c9ffd44fe7f6755 Mon Sep 17 00:00:00 2001 From: synth3 <19573241+synth3@users.noreply.github.com> Date: Fri, 15 Mar 2024 19:29:58 +0100 Subject: [PATCH] Remove custom Hibernate dialect detection Closes #27954 Signed-off-by: synth3 <19573241+synth3@users.noreply.github.com> --- .../DefaultJpaConnectionProviderFactory.java | 46 ++----------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java b/model/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java index 6995bed57e..3132631bff 100755 --- a/model/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java +++ b/model/jpa/src/main/java/org/keycloak/connections/jpa/DefaultJpaConnectionProviderFactory.java @@ -210,8 +210,9 @@ public class DefaultJpaConnectionProviderFactory implements JpaConnectionProvide try { prepareOperationalInfo(connection); - String driverDialect = detectDialect(connection); - if (driverDialect != null) { + String driverDialect = config.get("driverDialect"); + // use configured dialect, else rely on Hibernate detection + if (driverDialect != null && !driverDialect.isBlank()) { 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) { logger.debugf("Started Hibernate statistics with the interval %s seconds", globalStatsIntervalSecs); TimerProvider timer = session.getProvider(TimerProvider.class);