Skip to content

Commit bfc7d16

Browse files
committed
roll back the connection used for creating the DatabaseConnectionInfoImpl
because it has autoCommit disabled, and this caused problems on Db2
1 parent 2279b52 commit bfc7d16

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
172172
final var poolConfig = agroalDataSource.getConfiguration().connectionPoolConfiguration();
173173
final var connectionConfig = poolConfig.connectionFactoryConfiguration();
174174
try ( var connection = agroalDataSource.getConnection() ) {
175-
return new DatabaseConnectionInfoImpl(
175+
final var info = new DatabaseConnectionInfoImpl(
176176
AgroalConnectionProvider.class,
177177
connectionConfig.jdbcUrl(),
178178
// Attempt to resolve the driver name from the dialect,
@@ -196,6 +196,10 @@ public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
196196
poolConfig.maxSize(),
197197
getFetchSize( connection )
198198
);
199+
if ( !connection.getAutoCommit() ) {
200+
connection.rollback();
201+
}
202+
return info;
199203
}
200204
catch (SQLException e) {
201205
throw new JDBCConnectionException( "Could not create connection", e );

hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ public void configure(Map<String, Object> properties) {
191191
DEFAULT_MAX_POOL_SIZE ),
192192
fetchSize
193193
);
194+
if ( !connection.getAutoCommit() ) {
195+
connection.rollback();
196+
}
194197
}
195198
catch (SQLException e) {
196199
throw new JDBCConnectionException( "Could not create connection", e );

hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ private static ConnectionCreator buildCreator(
172172
getInt( POOL_SIZE, configurationValues, 20 ),
173173
getFetchSize( connection )
174174
);
175+
if ( !connection.getAutoCommit() ) {
176+
connection.rollback();
177+
}
175178
}
176179
catch (SQLException e) {
177180
throw new JDBCConnectionException( "Could not create connection", e );

hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public boolean supportsAggressiveRelease() {
101101
@Override
102102
public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
103103
try ( var connection = hikariDataSource.getConnection() ) {
104-
return new DatabaseConnectionInfoImpl(
104+
final var info = new DatabaseConnectionInfoImpl(
105105
HikariCPConnectionProvider.class,
106106
hikariConfig.getJdbcUrl(),
107107
// Attempt to resolve the driver name from the dialect,
@@ -124,6 +124,10 @@ public DatabaseConnectionInfo getDatabaseConnectionInfo(Dialect dialect) {
124124
hikariConfig.getMaximumPoolSize(),
125125
getFetchSize( connection )
126126
);
127+
if ( !connection.getAutoCommit() ) {
128+
connection.rollback();
129+
}
130+
return info;
127131
}
128132
catch (SQLException e) {
129133
throw new JDBCConnectionException( "Could not create connection", e );

0 commit comments

Comments
 (0)