HHH-14326 Always close the connection even if releasing JDBC resources fails

Signed-off-by: Yoann Rodière <yoann@hibernate.org>
This commit is contained in:
Yoann Rodière 2021-01-14 10:36:15 +01:00 committed by Sanne Grinovero
parent 74433cdec3
commit e5c830da19
1 changed files with 8 additions and 4 deletions

View File

@ -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." ); " This might indicate a multi-threaded use of Hibernate in combination with managed resources, which is not supported." );
} }
try { try {
getResourceRegistry().releaseResources(); try {
if ( ! localVariableConnection.isClosed() ) { getResourceRegistry().releaseResources();
sqlExceptionHelper.logAndClearWarnings( localVariableConnection ); if ( !localVariableConnection.isClosed() ) {
sqlExceptionHelper.logAndClearWarnings( localVariableConnection );
}
}
finally {
jdbcConnectionAccess.releaseConnection( localVariableConnection );
} }
jdbcConnectionAccess.releaseConnection( localVariableConnection );
} }
catch (SQLException e) { catch (SQLException e) {
throw sqlExceptionHelper.convert( e, "Unable to release JDBC Connection" ); throw sqlExceptionHelper.convert( e, "Unable to release JDBC Connection" );