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

@ -214,13 +214,17 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple
throw new HibernateException( "Detected concurrent management of connection resources." + throw new HibernateException( "Detected concurrent management of connection resources." +
" 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 { try {
getResourceRegistry().releaseResources(); getResourceRegistry().releaseResources();
if ( ! localVariableConnection.isClosed() ) { if ( !localVariableConnection.isClosed() ) {
sqlExceptionHelper.logAndClearWarnings( localVariableConnection ); 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" );
} }