From 1877315ee394769f5b150a40d99cc76f4bf75c76 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 20 Mar 2012 08:40:50 -0500 Subject: [PATCH] HHH-7090 - Temporary session closing affects original session --- .../transaction/internal/TransactionCoordinatorImpl.java | 8 ++++---- .../src/main/java/org/hibernate/internal/SessionImpl.java | 7 ++++--- .../hibernate/test/connections/AggressiveReleaseTest.java | 6 ++---- .../java/org/hibernate/test/connections/Silly.hbm.xml | 4 ++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java index 0c025c68f5..2a74f9f725 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/transaction/internal/TransactionCoordinatorImpl.java @@ -85,8 +85,8 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator { TransactionContext transactionContext) { this.transactionContext = transactionContext; this.jdbcCoordinator = new JdbcCoordinatorImpl( userSuppliedConnection, this ); - this.transactionEnvironment = transactionContext.getTransactionEnvironment(); - this.transactionFactory = this.transactionEnvironment.getTransactionFactory(); + this.transactionEnvironment = transactionContext.getTransactionEnvironment(); + this.transactionFactory = this.transactionEnvironment.getTransactionFactory(); this.observers = new ArrayList(); this.synchronizationRegistry = new SynchronizationRegistryImpl(); reset(); @@ -105,8 +105,8 @@ public class TransactionCoordinatorImpl implements TransactionCoordinator { List observers) { this.transactionContext = transactionContext; this.jdbcCoordinator = jdbcCoordinator; - this.transactionEnvironment = transactionContext.getTransactionEnvironment(); - this.transactionFactory = this.transactionEnvironment.getTransactionFactory(); + this.transactionEnvironment = transactionContext.getTransactionEnvironment(); + this.transactionFactory = this.transactionEnvironment.getTransactionFactory(); this.observers = observers; this.synchronizationRegistry = new SynchronizationRegistryImpl(); reset(); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 3de33a68cc..8b1807b435 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -236,13 +236,14 @@ public final class SessionImpl extends AbstractSessionImpl implements EventSourc this.flushBeforeCompletionEnabled = flushBeforeCompletionEnabled; if ( transactionCoordinator == null ) { + this.isTransactionCoordinatorShared = false; + this.connectionReleaseMode = connectionReleaseMode; + this.autoJoinTransactions = autoJoinTransactions; + this.transactionCoordinator = new TransactionCoordinatorImpl( connection, this ); this.transactionCoordinator.getJdbcCoordinator().getLogicalConnection().addObserver( new ConnectionObserverStatsBridge( factory ) ); - this.isTransactionCoordinatorShared = false; - this.connectionReleaseMode = connectionReleaseMode; - this.autoJoinTransactions = autoJoinTransactions; } else { if ( connection != null ) { diff --git a/hibernate-core/src/test/java/org/hibernate/test/connections/AggressiveReleaseTest.java b/hibernate-core/src/test/java/org/hibernate/test/connections/AggressiveReleaseTest.java index 74f9689e56..1169d0ab75 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/connections/AggressiveReleaseTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/connections/AggressiveReleaseTest.java @@ -218,7 +218,7 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase { Session s = getSessionUnderTest(); s.beginTransaction(); - List entities = new ArrayList(); + List entities = new ArrayList(); for ( int i = 0; i < 10; i++ ) { Other other = new Other( "other-" + i ); Silly silly = new Silly( "silly-" + i, other ); @@ -227,9 +227,7 @@ public class AggressiveReleaseTest extends ConnectionManagementTestCase { } s.flush(); - Iterator itr = entities.iterator(); - while ( itr.hasNext() ) { - Silly silly = ( Silly ) itr.next(); + for ( Silly silly : entities ) { silly.setName( "new-" + silly.getName() ); silly.getOther().setName( "new-" + silly.getOther().getName() ); } diff --git a/hibernate-core/src/test/java/org/hibernate/test/connections/Silly.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/connections/Silly.hbm.xml index 0b155848ce..4ec5d50a74 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/connections/Silly.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/connections/Silly.hbm.xml @@ -7,7 +7,7 @@ - + @@ -15,7 +15,7 @@ - +