Skip to content

Commit 62d727d

Browse files
committed
Fix connection leak in connection provider used for JTA tests
1 parent a8cddb9 commit 62d727d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

hibernate-testing/src/main/java/org/hibernate/testing/jta/JtaAwareConnectionProviderImpl.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ public Connection getConnection() throws SQLException {
9393
if ( connection == null ) {
9494
connection = delegate.getConnection();
9595
TestingJtaPlatformImpl.synchronizationRegistry().putResource( CONNECTION_KEY, connection );
96-
97-
XAResourceWrapper xaResourceWrapper = new XAResourceWrapper( this, connection );
98-
currentTransaction.enlistResource( xaResourceWrapper );
96+
try {
97+
XAResourceWrapper xaResourceWrapper = new XAResourceWrapper( this, connection );
98+
currentTransaction.enlistResource( xaResourceWrapper );
99+
}
100+
catch (Exception e) {
101+
delist( connection );
102+
throw e;
103+
}
99104
}
100105
return connection;
101106
}

0 commit comments

Comments
 (0)