|
20 | 20 |
|
21 | 21 | import org.hibernate.testing.boot.BasicTestingJdbcServiceImpl; |
22 | 22 | import org.hibernate.testing.orm.junit.BaseSessionFactoryFunctionalTest; |
| 23 | +import org.hibernate.testing.orm.junit.Jira; |
23 | 24 | import org.hibernate.testing.orm.junit.RequiresDialect; |
24 | 25 | import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider; |
25 | 26 | import org.junit.jupiter.api.AfterEach; |
@@ -118,9 +119,9 @@ protected void cleanupTest() throws Exception { |
118 | 119 |
|
119 | 120 | @Test |
120 | 121 | public void testBasicRelease() { |
121 | | - connectionProvider.clear(); |
122 | 122 | ResourceRegistry registry = sessionFactoryScope().fromSession( |
123 | 123 | session -> { |
| 124 | + connectionProvider.clear(); |
124 | 125 | JdbcCoordinatorImpl jdbcCoord = (JdbcCoordinatorImpl) session.getJdbcCoordinator(); |
125 | 126 | ResourceRegistry resourceRegistry = jdbcCoord.getLogicalConnection().getResourceRegistry(); |
126 | 127 | try { |
@@ -154,9 +155,9 @@ public void testBasicRelease() { |
154 | 155 |
|
155 | 156 | @Test |
156 | 157 | public void testReleaseCircumventedByHeldResources() { |
157 | | - connectionProvider.clear(); |
158 | 158 | ResourceRegistry registry = sessionFactoryScope().fromSession( |
159 | 159 | session -> { |
| 160 | + connectionProvider.clear(); |
160 | 161 | JdbcCoordinatorImpl jdbcCoord = (JdbcCoordinatorImpl) session.getJdbcCoordinator(); |
161 | 162 | ResourceRegistry resourceRegistry = jdbcCoord.getLogicalConnection().getResourceRegistry(); |
162 | 163 |
|
@@ -217,10 +218,9 @@ public void testReleaseCircumventedByHeldResources() { |
217 | 218 |
|
218 | 219 | @Test |
219 | 220 | public void testReleaseCircumventedManually() { |
220 | | - connectionProvider.clear(); |
221 | | - connectionProvider.clear(); |
222 | 221 | ResourceRegistry registry = sessionFactoryScope().fromSession( |
223 | 222 | session -> { |
| 223 | + connectionProvider.clear(); |
224 | 224 | JdbcCoordinatorImpl jdbcCoord = (JdbcCoordinatorImpl) session.getJdbcCoordinator(); |
225 | 225 | ResourceRegistry resourceRegistry = jdbcCoord.getLogicalConnection().getResourceRegistry(); |
226 | 226 |
|
@@ -271,4 +271,20 @@ public void testReleaseCircumventedManually() { |
271 | 271 | assertEquals( 0, connectionProvider.getAcquiredConnections().size() ); |
272 | 272 | assertEquals( 2, connectionProvider.getReleasedConnections().size() ); |
273 | 273 | } |
| 274 | + |
| 275 | + @Test |
| 276 | + @Jira("https://hibernate.atlassian.net/browse/HHH-19477") |
| 277 | + public void testHql() { |
| 278 | + sessionFactoryScope().inTransaction( session -> { |
| 279 | + connectionProvider.clear(); |
| 280 | + JdbcCoordinatorImpl jdbcCoord = (JdbcCoordinatorImpl) session.getJdbcCoordinator(); |
| 281 | + ResourceRegistry resourceRegistry = jdbcCoord.getLogicalConnection().getResourceRegistry(); |
| 282 | + |
| 283 | + session.createSelectionQuery( "select 1" ).uniqueResult(); |
| 284 | + |
| 285 | + assertFalse( resourceRegistry.hasRegisteredResources() ); |
| 286 | + assertEquals( 0, connectionProvider.getAcquiredConnections().size() ); |
| 287 | + assertEquals( 1, connectionProvider.getReleasedConnections().size() ); |
| 288 | + } ); |
| 289 | + } |
274 | 290 | } |
0 commit comments