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 0d5dd3876b..0101585b92 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 @@ -82,7 +82,8 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { */ public JdbcCoordinatorImpl( Connection userSuppliedConnection, - JdbcSessionOwner owner) { + JdbcSessionOwner owner, + JdbcServices jdbcServices) { this.isUserSuppliedConnection = userSuppliedConnection != null; final ResourceRegistry resourceRegistry = new ResourceRegistryStandardImpl( @@ -95,13 +96,12 @@ public class JdbcCoordinatorImpl implements JdbcCoordinator { this.logicalConnection = new LogicalConnectionManagedImpl( owner.getJdbcConnectionAccess(), owner.getJdbcSessionContext(), - resourceRegistry + resourceRegistry, + jdbcServices ); } this.owner = owner; - this.jdbcServices = owner.getJdbcSessionContext() - .getServiceRegistry() - .getService( JdbcServices.class ); + this.jdbcServices = jdbcServices; } private JdbcCoordinatorImpl( diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 7384264360..847105cbb6 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -210,7 +210,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont else { this.isTransactionCoordinatorShared = false; this.autoJoinTransactions = options.shouldAutoJoinTransactions(); - this.jdbcCoordinator = new JdbcCoordinatorImpl( options.getConnection(), this ); + this.jdbcCoordinator = new JdbcCoordinatorImpl( options.getConnection(), this, fastSessionServices.jdbcServices ); this.transactionCoordinator = fastSessionServices.transactionCoordinatorBuilder.buildTransactionCoordinator( jdbcCoordinator, this ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java index bdda279fd7..7a42c4f82c 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java @@ -86,6 +86,7 @@ final class FastSessionServices { final MultiTenantConnectionProvider multiTenantConnectionProvider; final ClassLoaderService classLoaderService; final TransactionCoordinatorBuilder transactionCoordinatorBuilder; + final JdbcServices jdbcServices; //Private fields: private final Dialect dialect; @@ -128,6 +129,7 @@ final class FastSessionServices { this.multiTenantConnectionProvider = requiresMultiTenantConnectionProvider ? sr.getService( MultiTenantConnectionProvider.class ) : null; this.classLoaderService = sr.getService( ClassLoaderService.class ); this.transactionCoordinatorBuilder = sr.getService( TransactionCoordinatorBuilder.class ); + this.jdbcServices = sr.getService( JdbcServices.class ); } Iterable getClearEventListeners() { diff --git a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java index 18b5774ece..2a4cb84d5d 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/internal/LogicalConnectionManagedImpl.java @@ -48,20 +48,17 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple public LogicalConnectionManagedImpl( JdbcConnectionAccess jdbcConnectionAccess, JdbcSessionContext jdbcSessionContext, - ResourceRegistry resourceRegistry) { + ResourceRegistry resourceRegistry, + JdbcServices jdbcServices) { this.jdbcConnectionAccess = jdbcConnectionAccess; this.observer = jdbcSessionContext.getObserver(); this.resourceRegistry = resourceRegistry; this.connectionHandlingMode = determineConnectionHandlingMode( jdbcSessionContext.getPhysicalConnectionHandlingMode(), - jdbcConnectionAccess + jdbcConnectionAccess ); - ); - - this.sqlExceptionHelper = jdbcSessionContext.getServiceRegistry() - .getService( JdbcServices.class ) - .getSqlExceptionHelper(); + this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper(); if ( connectionHandlingMode.getAcquisitionMode() == ConnectionAcquisitionMode.IMMEDIATELY ) { acquireConnectionIfNeeded(); @@ -94,7 +91,9 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple JdbcConnectionAccess jdbcConnectionAccess, JdbcSessionContext jdbcSessionContext, boolean closed) { - this( jdbcConnectionAccess, jdbcSessionContext, new ResourceRegistryStandardImpl() ); + this( jdbcConnectionAccess, jdbcSessionContext, new ResourceRegistryStandardImpl(), + jdbcSessionContext.getServiceRegistry().getService( JdbcServices.class ) + ); this.closed = closed; } @@ -221,7 +220,7 @@ public class LogicalConnectionManagedImpl extends AbstractLogicalConnectionImple public static LogicalConnectionManagedImpl deserialize( ObjectInputStream ois, JdbcConnectionAccess jdbcConnectionAccess, - JdbcSessionContext jdbcSessionContext) throws IOException, ClassNotFoundException { + JdbcSessionContext jdbcSessionContext) throws IOException { final boolean isClosed = ois.readBoolean(); return new LogicalConnectionManagedImpl( jdbcConnectionAccess, jdbcSessionContext, isClosed ); } diff --git a/hibernate-core/src/test/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorTest.java b/hibernate-core/src/test/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorTest.java index df1646aa58..50a8334265 100644 --- a/hibernate-core/src/test/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorTest.java +++ b/hibernate-core/src/test/java/org/hibernate/engine/jdbc/internal/JdbcCoordinatorTest.java @@ -62,8 +62,6 @@ public class JdbcCoordinatorTest { when( sessionContext.getObserver() ).thenReturn( jdbcObserver ); JdbcServices jdbcServices = Mockito.mock( JdbcServices.class ); - when( serviceRegistry.getService( eq( JdbcServices.class ) ) ).thenReturn( - jdbcServices ); ConfigurationService configurationService = Mockito.mock( ConfigurationService.class ); when( serviceRegistry.getService( eq( ConfigurationService.class ) ) ).thenReturn( @@ -77,7 +75,8 @@ public class JdbcCoordinatorTest { JdbcCoordinatorImpl jdbcCoordinator = new JdbcCoordinatorImpl( null, - sessionOwner + sessionOwner, + jdbcServices ); Batch currentBatch = Mockito.mock( Batch.class );