hibernate/hibernate-orm · error · IllegalArgumentException
cannot reconnect using a null connection
Error message
cannot reconnect using a null connection
What it means
IllegalArgumentException from LogicalConnectionProvidedImpl.manualReconnect(): session.reconnect(null) was called. The parameter is declared @Nonnull and this is a defensive rejection of a null connection; the transaction state is untouched.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionProvidedImpl.java:118
}
@Override
public Connection manualDisconnect() {
errorIfClosed();
try {
resourceRegistry.releaseResources();
return providedConnection;
}
finally {
providedConnection = null;
}
}
@Override
public void manualReconnect(@Nonnull Connection connection) {
errorIfClosed();
if ( connection == null ) {
throw new IllegalArgumentException( "cannot reconnect using a null connection" );
}
else if ( connection == providedConnection ) {
// likely an unmatched reconnect call (no matching disconnect call)
CONNECTION_LOGGER.reconnectingSameConnectionAlreadyConnected();
}
else if ( providedConnection != null ) {
throw new IllegalArgumentException(
"Cannot reconnect to a new user-supplied connection because currently connected; must disconnect before reconnecting."
);
}
providedConnection = connection;
CONNECTION_LOGGER.manuallyReconnectedLogicalConnection();
}
@Override
protected Connection getConnectionForTransactionManagement() {
return providedConnection;
}View on GitHub (pinned to fad1729dce)
Solutions
- Null-check before reconnecting and fail with context (which producer returned null)
- Fix the connection producer that returned null
- For brand-new sessions use sessionFactory.openSession(connection) instead of reconnect
Example fix
// before session.reconnect(getConnection()); // may pass null // after Connection c = Objects.requireNonNull(getConnection(), "connection source returned null"); session.reconnect(c);
Defensive patterns
Strategy: validation
Validate before calling
Connection c = Objects.requireNonNull(connectionSource.get(), "connection source returned null"); session.reconnect(c);
Try / catch
catch (IllegalArgumentException e) {
// null reached reconnect(): fix the nullable producer or guard above; nothing stateful happened
} Prevention
- Never store connections in nullable fields that later feed reconnect()
- Make test stubs return non-null connections
- Centralize connection acquisition in one non-null-returning component
When it happens
Trigger: session.reconnect(null), e.g. reconnect(dataSource.getConnection()) where the producer returned null, or wrapper code forwarding a nullable stored connection field.
Common situations: Framework/wrapper code holding a nullable connection reference; stubs and test harnesses returning null from getConnection(); race where the connection field is cleared before reconnect runs.
Related errors
- Provided Connection cannot be null
- CacheMode cannot be null
- Passed table name cannot be null
- Informix only supports the case insensitive flag 'i' as lite
- The specified package name cannot be null
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/a1a4e4329aca4237.
Report an issue: GitHub.