Hibernate transaction can't recover from a DB restart

Description

I think the bug is in JdbcTransaction.releaseManagedConnection
if for whatever reason the connection get's closed, the setAutoCommit will throw and exception and the managedConnection isn't reset.
Even retrying to start the transaction will fail because it is bind the the current thread.

Solution should be that managedConnection=null is moved after the catch so the post condition is always that managedConnection = null

private void releaseManagedConnection() {
try {
if ( wasInitiallyAutoCommit ) {
LOG.debug( "re-enabling autocommit" );
managedConnection.setAutoCommit( true );
}
managedConnection = null;
}
catch ( Exception e ) {
LOG.debug( "Could not toggle autocommit", e );
}
}

Environment

Any 4.2 or higher versions.

Status

Assignee

Unassigned

Reporter

Leon.V

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.11

Priority

Critical
Configure