From e5c830da19cbfa57c5a23b2d884244f280d586e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Thu, 14 Jan 2021 10:36:15 +0100 Subject: [PATCH] HHH-14326 Always close the connection even if releasing JDBC resources fails MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Yoann Rodière --- .../jdbc/internal/LogicalConnectionManagedImpl.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java index 3584b6d6c3..d7f45d0636 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java @@ -215,11 +215,15 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple " This might indicate a multi-threaded use of Hibernate in combination with managed resources, which is not supported." ); } try { - getResourceRegistry().releaseResources(); - if ( ! localVariableConnection.isClosed() ) { - sqlExceptionHelper.logAndClearWarnings( localVariableConnection ); + try { + getResourceRegistry().releaseResources(); + if ( !localVariableConnection.isClosed() ) { + sqlExceptionHelper.logAndClearWarnings( localVariableConnection ); + } + } + finally { + jdbcConnectionAccess.releaseConnection( localVariableConnection ); } - jdbcConnectionAccess.releaseConnection( localVariableConnection ); } catch (SQLException e) { throw sqlExceptionHelper.convert( e, "Unable to release JDBC Connection" );