diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java index 45583f3fb2..4985b00119 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/SqlExceptionHelper.java @@ -284,12 +284,17 @@ public class SqlExceptionHelper { @SuppressWarnings( {"ThrowableResultOfMethodCallIgnored"} ) public void handleAndClearWarnings( Statement statement, WarningHandler handler ) { - try { - walkWarnings(statement.getWarnings(), handler); - } catch (SQLException sqlException) { - // workaround for WebLogic - LOG.debug("could not log warnings", sqlException); - } + // See HHH-9174. Statement#getWarnings can be an expensive call for many JDBC libs. Don't do it unless + // the log level would actually allow a warning to be logged. + if (LOG.isEnabled(Level.WARN)) { + try { + walkWarnings(statement.getWarnings(), handler); + } catch (SQLException sqlException) { + // workaround for WebLogic + LOG.debug("could not log warnings", sqlException); + } + } + try { // Sybase fail if we don't do that, sigh... statement.clearWarnings();