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 28abfb9cac..e4f223aecf 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java @@ -66,6 +66,7 @@ import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.jpa.internal.util.LockOptionsHelper; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; import org.hibernate.service.spi.ServiceRegistryImplementor; +import org.hibernate.sql.ast.spi.ParameterMarkerStrategy; import org.hibernate.type.format.FormatMapper; import jakarta.persistence.CacheRetrieveMode; @@ -171,6 +172,7 @@ public final class FastSessionServices { public final EntityCopyObserverFactory entityCopyObserverFactory; public final BatchBuilder batchBuilder; public final Dialect dialect; + public final ParameterMarkerStrategy parameterMarkerStrategy; //Private fields: private final CacheStoreMode defaultCacheStoreMode; @@ -232,6 +234,7 @@ public final class FastSessionServices { this.defaultTimeZoneStorageStrategy = sessionFactoryOptions.getDefaultTimeZoneStorageStrategy(); this.defaultJdbcBatchSize = sessionFactoryOptions.getJdbcBatchSize(); this.requiresMultiTenantConnectionProvider = sessionFactory.getSessionFactoryOptions().isMultiTenancyEnabled(); + this.parameterMarkerStrategy = serviceRegistry.getService( ParameterMarkerStrategy.class ); //Some "hot" services: this.connectionProvider = requiresMultiTenantConnectionProvider diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Delete.java b/hibernate-core/src/main/java/org/hibernate/sql/Delete.java index 0b6167e4fc..60a55c4b55 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Delete.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Delete.java @@ -29,7 +29,7 @@ public class Delete implements RestrictionRenderingContext { private int parameterCount; public Delete(SessionFactoryImplementor factory) { - this( factory.getServiceRegistry().getService( ParameterMarkerStrategy.class ) ); + this( factory.getFastSessionServices().parameterMarkerStrategy ); } public Delete(ParameterMarkerStrategy parameterMarkerStrategy) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Insert.java b/hibernate-core/src/main/java/org/hibernate/sql/Insert.java index 6c8ea70c8e..8d303f7dbe 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Insert.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Insert.java @@ -38,8 +38,8 @@ public class Insert { public Insert(SessionFactoryImplementor sessionFactory) { this( - sessionFactory.getJdbcServices().getDialect(), - sessionFactory.getServiceRegistry().getService( ParameterMarkerStrategy.class ) + sessionFactory.getFastSessionServices().dialect, + sessionFactory.getFastSessionServices().parameterMarkerStrategy ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/SimpleSelect.java b/hibernate-core/src/main/java/org/hibernate/sql/SimpleSelect.java index 10b73428a3..bf36413939 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/SimpleSelect.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/SimpleSelect.java @@ -18,6 +18,7 @@ import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.dialect.Dialect; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.internal.FastSessionServices; import org.hibernate.sql.ast.spi.ParameterMarkerStrategy; /** @@ -42,8 +43,20 @@ public class SimpleSelect implements RestrictionRenderingContext { private int parameterCount; public SimpleSelect(SessionFactoryImplementor factory) { - this.dialect = factory.getJdbcServices().getDialect(); - this.parameterMarkerStrategy = factory.getServiceRegistry().getService( ParameterMarkerStrategy.class ); + this.dialect = lookupDialect( factory ); + this.parameterMarkerStrategy = lookupParameterMarkerStrategy( factory ); + } + + //A SimpleSelect constructor might be invoked before the FastSessionServices are defined + private static Dialect lookupDialect(final SessionFactoryImplementor factory) { + final FastSessionServices fastSessionServices = factory.getFastSessionServices(); + return fastSessionServices != null ? fastSessionServices.dialect : factory.getJdbcServices().getDialect(); + } + + //A SimpleSelect constructor might be invoked before the FastSessionServices are defined + private static ParameterMarkerStrategy lookupParameterMarkerStrategy(final SessionFactoryImplementor factory) { + final FastSessionServices fastSessionServices = factory.getFastSessionServices(); + return fastSessionServices != null ? fastSessionServices.parameterMarkerStrategy : factory.getServiceRegistry().getService( ParameterMarkerStrategy.class ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/Update.java b/hibernate-core/src/main/java/org/hibernate/sql/Update.java index 68ee353d90..950a7c71e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/Update.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/Update.java @@ -32,7 +32,7 @@ public class Update implements RestrictionRenderingContext { private int parameterCount; public Update(SessionFactoryImplementor factory) { - this( factory.getServiceRegistry().getService( ParameterMarkerStrategy.class ) ); + this( factory.getFastSessionServices().parameterMarkerStrategy ); } public Update(ParameterMarkerStrategy parameterMarkerStrategy) {