diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadSelectLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadSelectLockingStrategy.java index 84580470aa..d12a80cece 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadSelectLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticReadSelectLockingStrategy.java @@ -96,7 +96,7 @@ public class PessimisticReadSelectLockingStrategy extends AbstractSelectLockingS } } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteSelectLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteSelectLockingStrategy.java index 660dbdaf6e..d810aa2eec 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteSelectLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/PessimisticWriteSelectLockingStrategy.java @@ -95,7 +95,7 @@ public class PessimisticWriteSelectLockingStrategy extends AbstractSelectLocking } } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/lock/SelectLockingStrategy.java b/hibernate-core/src/main/java/org/hibernate/dialect/lock/SelectLockingStrategy.java index 7e7926da46..8e44214a99 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/lock/SelectLockingStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/lock/SelectLockingStrategy.java @@ -96,7 +96,7 @@ public class SelectLockingStrategy extends AbstractSelectLockingStrategy { } } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java index 082f05c9fd..04265dff1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorImpl.java @@ -374,7 +374,7 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { LOG.tracev( "Registering result set [{0}]", resultSet ); if ( statement == null ) { try { - statement = resultSet.getStatement(); // best guess + statement = resultSet.getStatement(); } catch ( SQLException e ) { throw exceptionHelper.convert( e, "unable to access statement from resultset" ); @@ -397,14 +397,15 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { } @Override - public void release(ResultSet resultSet) { + public void release(ResultSet resultSet, Statement statement) { LOG.tracev( "Releasing result set [{0}]", resultSet ); - Statement statement; - try { - statement = resultSet.getStatement(); - } - catch ( SQLException e ) { - throw exceptionHelper.convert( e, "unable to access statement from resultset" ); + if ( statement == null ) { + try { + statement = resultSet.getStatement(); + } + catch ( SQLException e ) { + throw exceptionHelper.convert( e, "unable to access statement from resultset" ); + } } if ( statement != null ) { if ( LOG.isEnabled( Level.WARN ) && !xref.containsKey( statement ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcCoordinator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcCoordinator.java index 6b40bf5c75..e9c8a48d45 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcCoordinator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/spi/JdbcCoordinator.java @@ -184,8 +184,9 @@ public interface JdbcCoordinator extends Serializable { * Release a previously registered result set. * * @param resultSet The result set to release. + * @param statement Statement from which {@link ResultSet} has been generated. */ - public void release(ResultSet resultSet); + public void release(ResultSet resultSet, Statement statement); /** * Does this registry currently have any registered resources? diff --git a/hibernate-core/src/main/java/org/hibernate/id/GUIDGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/GUIDGenerator.java index d1b4053d2a..d294fad8c5 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/GUIDGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/GUIDGenerator.java @@ -64,7 +64,7 @@ public class GUIDGenerator implements IdentifierGenerator { result = rs.getString(1); } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } LOG.guidGenerated(result); return result; diff --git a/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java index 4f59cd2575..943fde8249 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IdentityGenerator.java @@ -105,7 +105,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator { } finally { if ( rs != null ) { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, insert ); } } } @@ -150,7 +150,7 @@ public class IdentityGenerator extends AbstractPostInsertGenerator { ); } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, insert ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/id/IncrementGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/IncrementGenerator.java index 7e9467f5d9..584a84d390 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IncrementGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IncrementGenerator.java @@ -136,7 +136,7 @@ public class IncrementGenerator implements IdentifierGenerator, Configurable { } } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java index 63232718e9..2f726f393d 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/SequenceGenerator.java @@ -128,7 +128,7 @@ public class SequenceGenerator return result; } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java index 0aa427f1bb..23ec0ce368 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java @@ -107,7 +107,7 @@ public class SequenceStructure implements DatabaseStructure { } finally { try { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } catch( Throwable ignore ) { // intentionally empty diff --git a/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java b/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java index 8af7a758c9..f783721b77 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java +++ b/hibernate-core/src/main/java/org/hibernate/id/insert/AbstractSelectingDelegate.java @@ -87,7 +87,7 @@ public abstract class AbstractSelectingDelegate implements InsertGeneratedIdenti return getResult( session, rs, binder.getEntity() ); } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, idSelect ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 7b4861d5ed..5236a08712 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -1796,7 +1796,7 @@ public abstract class AbstractCollectionPersister return rs.next() ? rs.getInt( 1 ) - baseIndex : 0; } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { @@ -1835,7 +1835,7 @@ public abstract class AbstractCollectionPersister return rs.next(); } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } catch ( TransientObjectException e ) { @@ -1874,7 +1874,7 @@ public abstract class AbstractCollectionPersister } } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 8beed0980b..860f4b74b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -1278,7 +1278,7 @@ public abstract class AbstractEntityPersister } finally { if ( rs != null ) { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps ); } } } @@ -1535,7 +1535,7 @@ public abstract class AbstractEntityPersister return values; } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps ); } } finally { @@ -1586,7 +1586,7 @@ public abstract class AbstractEntityPersister return (Serializable) getIdentifierType().nullSafeGet( rs, getIdentifierAliases(), session, null ); } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps ); } } finally { @@ -1890,7 +1890,7 @@ public abstract class AbstractEntityPersister return getVersionType().nullSafeGet( rs, getVersionColumnName(), session, null ); } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, st ); } } finally { @@ -2910,7 +2910,7 @@ public abstract class AbstractEntityPersister } if ( sequentialResultSet != null ) { - session.getTransactionCoordinator().getJdbcCoordinator().release( sequentialResultSet ); + session.getTransactionCoordinator().getJdbcCoordinator().release( sequentialResultSet, sequentialSelect ); } return values; @@ -4654,7 +4654,7 @@ public abstract class AbstractEntityPersister } finally { if ( rs != null ) { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps ); } } } @@ -4753,7 +4753,7 @@ public abstract class AbstractEntityPersister return snapshot; } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps ); } } finally { @@ -4811,7 +4811,7 @@ public abstract class AbstractEntityPersister return (Serializable) getIdentifierType().hydrate( rs, getIdentifierAliases(), session, null ); } finally { - session.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + session.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps ); } } finally { diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/dataTypes/BasicOperationsTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/dataTypes/BasicOperationsTest.java index a826cca824..990bcd8728 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/dataTypes/BasicOperationsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/dataTypes/BasicOperationsTest.java @@ -132,7 +132,7 @@ public class BasicOperationsTest extends BaseCoreFunctionalTestCase { s.getTransactionCoordinator().getJdbcCoordinator().register(columnInfo, columnInfo.getStatement()); assertTrue( columnInfo.next() ); int dataType = columnInfo.getInt( "DATA_TYPE" ); - s.getTransactionCoordinator().getJdbcCoordinator().release( columnInfo ); + s.getTransactionCoordinator().getJdbcCoordinator().release( columnInfo, columnInfo.getStatement() ); assertEquals( columnName, JdbcTypeNameMapper.getTypeName( expectedJdbcTypeCode ), diff --git a/hibernate-core/src/test/java/org/hibernate/test/jdbc/GeneralWorkTest.java b/hibernate-core/src/test/java/org/hibernate/test/jdbc/GeneralWorkTest.java index 34e73d9c25..17f2fb9f2f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jdbc/GeneralWorkTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jdbc/GeneralWorkTest.java @@ -72,13 +72,13 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase { resultSet = ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( statement, "select * from T_JDBC_PERSON" ); } finally { - releaseQuietly( ((SessionImplementor)session), resultSet ); + releaseQuietly( ((SessionImplementor)session), resultSet, statement ); } try { ((SessionImplementor)session).getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().extract( statement, "select * from T_JDBC_BOAT" ); } finally { - releaseQuietly( ((SessionImplementor)session), resultSet ); + releaseQuietly( ((SessionImplementor)session), resultSet, statement ); } } finally { @@ -145,7 +145,7 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase { assertEquals( 1L, personCount ); } finally { - releaseQuietly( ((SessionImplementor)session2), resultSet ); + releaseQuietly( ((SessionImplementor)session2), resultSet, statement ); } } finally { @@ -178,12 +178,12 @@ public class GeneralWorkTest extends BaseCoreFunctionalTestCase { } } - private void releaseQuietly(SessionImplementor s, ResultSet resultSet) { + private void releaseQuietly(SessionImplementor s, ResultSet resultSet, Statement statement) { if ( resultSet == null ) { return; } try { - s.getTransactionCoordinator().getJdbcCoordinator().release( resultSet ); + s.getTransactionCoordinator().getJdbcCoordinator().release( resultSet, statement ); } catch (Exception e) { // ignore diff --git a/hibernate-core/src/test/java/org/hibernate/test/sql/autodiscovery/AutoDiscoveryTest.java b/hibernate-core/src/test/java/org/hibernate/test/sql/autodiscovery/AutoDiscoveryTest.java index 9a99586576..01dc7f47dd 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/sql/autodiscovery/AutoDiscoveryTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/sql/autodiscovery/AutoDiscoveryTest.java @@ -136,7 +136,7 @@ public class AutoDiscoveryTest extends BaseCoreFunctionalTestCase { Assert.assertFalse( "bad dialect.getColumnAliasExtractor impl", column1Alias.equals( column2Alias ) ); } finally { - sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( rs ); + sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( rs, ps ); sessionImplementor.getTransactionCoordinator().getJdbcCoordinator().release( ps ); } }