remove hibernate.query.validate_parameters

in H6 we're going to always validate them
This commit is contained in:
Gavin King 2022-01-20 22:07:22 +01:00
parent a59bf70ccf
commit d385cc8825
20 changed files with 17 additions and 215 deletions

View File

@ -492,10 +492,6 @@ Can reference a
`StatementInspector` implementation `Class` reference or `StatementInspector` implementation `Class` reference or
`StatementInspector` implementation class name (fully-qualified class name). `StatementInspector` implementation class name (fully-qualified class name).
`*hibernate.query.validate_parameters*` (e.g. `true` (default value) or `false`)::
This configuration property can be used to disable parameters validation performed by `org.hibernate.query.Query#setParameter` when the Session is bootstrapped via Jakarta Persistence
`jakarta.persistence.EntityManagerFactory`.
`*hibernate.criteria.value_handling_mode*` (e.g. `BIND` (default value) or `INLINE`):: `*hibernate.criteria.value_handling_mode*` (e.g. `BIND` (default value) or `INLINE`)::
By default, Criteria queries uses bind parameters for any value passed through the Jakarta Persistence Criteria API. By default, Criteria queries uses bind parameters for any value passed through the Jakarta Persistence Criteria API.
+ +

View File

@ -135,22 +135,6 @@ public interface SessionBuilder<T extends SessionBuilder> {
T jdbcTimeZone(TimeZone timeZone); T jdbcTimeZone(TimeZone timeZone);
/**
* Should {@link Query#setParameter} perform parameter validation
* when the Session is bootstrapped via JPA {@link jakarta.persistence.EntityManagerFactory}
*
* @param enabled {@code true} indicates the validation should be performed, {@code false} otherwise
* <p>
* The default value is {@code true}
*
* @return {@code this}, for method chaining
*/
default T setQueryParameterValidation(boolean enabled) {
return (T) this;
}
/** /**
* Should the session be automatically closed after transaction completion? * Should the session be automatically closed after transaction completion?
* *

View File

@ -40,18 +40,4 @@ public interface StatelessSessionBuilder<T extends StatelessSessionBuilder> {
* @return {@code this}, for method chaining * @return {@code this}, for method chaining
*/ */
T tenantIdentifier(String tenantIdentifier); T tenantIdentifier(String tenantIdentifier);
/**
* Should {@link Query#setParameter} perform parameter validation
* when the Session is bootstrapped via JPA {@link jakarta.persistence.EntityManagerFactory}
*
* @param enabled {@code true} indicates the validation should be performed, {@code false} otherwise
* <p>
* The default value is {@code true}
*
* @return {@code this}, for method chaining
*/
default T setQueryParameterValidation(boolean enabled) {
return (T) this;
}
} }

View File

@ -132,7 +132,6 @@ import static org.hibernate.cfg.AvailableSettings.USE_SCROLLABLE_RESULTSET;
import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE; import static org.hibernate.cfg.AvailableSettings.USE_SECOND_LEVEL_CACHE;
import static org.hibernate.cfg.AvailableSettings.USE_SQL_COMMENTS; import static org.hibernate.cfg.AvailableSettings.USE_SQL_COMMENTS;
import static org.hibernate.cfg.AvailableSettings.USE_STRUCTURED_CACHE; import static org.hibernate.cfg.AvailableSettings.USE_STRUCTURED_CACHE;
import static org.hibernate.cfg.AvailableSettings.VALIDATE_QUERY_PARAMETERS;
import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN; import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN;
import static org.hibernate.internal.CoreLogging.messageLogger; import static org.hibernate.internal.CoreLogging.messageLogger;
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
@ -246,7 +245,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
private PhysicalConnectionHandlingMode connectionHandlingMode; private PhysicalConnectionHandlingMode connectionHandlingMode;
private boolean connectionProviderDisablesAutoCommit; private boolean connectionProviderDisablesAutoCommit;
private TimeZone jdbcTimeZone; private TimeZone jdbcTimeZone;
private boolean queryParametersValidationEnabled;
private ValueHandlingMode criteriaValueHandlingMode; private ValueHandlingMode criteriaValueHandlingMode;
private ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode; private ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode;
// These two settings cannot be modified from the builder, // These two settings cannot be modified from the builder,
@ -558,12 +556,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
throw new IllegalArgumentException( "Configuration property " + JDBC_TIME_ZONE + " value [" + jdbcTimeZoneValue + "] is not supported!" ); throw new IllegalArgumentException( "Configuration property " + JDBC_TIME_ZONE + " value [" + jdbcTimeZoneValue + "] is not supported!" );
} }
this.queryParametersValidationEnabled = ConfigurationHelper.getBoolean(
VALIDATE_QUERY_PARAMETERS,
configurationSettings,
true
);
this.criteriaValueHandlingMode = ValueHandlingMode.interpret( this.criteriaValueHandlingMode = ValueHandlingMode.interpret(
configurationSettings.get( CRITERIA_VALUE_HANDLING_MODE ) configurationSettings.get( CRITERIA_VALUE_HANDLING_MODE )
); );
@ -1168,11 +1160,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
return this.jdbcTimeZone; return this.jdbcTimeZone;
} }
@Override
public boolean isQueryParametersValidationEnabled() {
return this.queryParametersValidationEnabled;
}
@Override @Override
public ValueHandlingMode getCriteriaValueHandlingMode() { public ValueHandlingMode getCriteriaValueHandlingMode() {
return criteriaValueHandlingMode; return criteriaValueHandlingMode;

View File

@ -385,11 +385,6 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp
return delegate.getJdbcTimeZone(); return delegate.getJdbcTimeZone();
} }
@Override
public boolean isQueryParametersValidationEnabled() {
return delegate.isQueryParametersValidationEnabled();
}
@Override @Override
public ValueHandlingMode getCriteriaValueHandlingMode() { public ValueHandlingMode getCriteriaValueHandlingMode() {
return delegate.getCriteriaValueHandlingMode(); return delegate.getCriteriaValueHandlingMode();

View File

@ -252,10 +252,6 @@ public interface SessionFactoryOptions extends QueryEngineOptions {
TimeZone getJdbcTimeZone(); TimeZone getJdbcTimeZone();
default boolean isQueryParametersValidationEnabled(){
return isJpaBootstrap();
}
default ValueHandlingMode getCriteriaValueHandlingMode() { default ValueHandlingMode getCriteriaValueHandlingMode() {
return ValueHandlingMode.BIND; return ValueHandlingMode.BIND;
} }

View File

@ -1968,20 +1968,6 @@ public interface AvailableSettings {
*/ */
String MERGE_ENTITY_COPY_OBSERVER = "hibernate.event.merge.entity_copy_observer"; String MERGE_ENTITY_COPY_OBSERVER = "hibernate.event.merge.entity_copy_observer";
/**
* Setting which indicates if {@link Query#setParameter} should not perform parameters validation
*
* This setting is applied only when the Session is bootstrapped via JPA {@link jakarta.persistence.EntityManagerFactory}
*
* </p>
* Values are: {@code true} indicates the validation should be performed, {@code false} otherwise
* <p>
* The default value is {@code true} when the Session is bootstrapped via JPA {@link jakarta.persistence.EntityManagerFactory},
* otherwise is {@code false}
*
*/
String VALIDATE_QUERY_PARAMETERS = "hibernate.query.validate_parameters";
/** /**
* By default, Criteria queries uses bind parameters for any value passed through the JPA Criteria API. * By default, Criteria queries uses bind parameters for any value passed through the JPA Criteria API.
* *

View File

@ -121,12 +121,6 @@ public abstract class AbstractDelegatingSessionBuilder<T extends SessionBuilder>
return getThis(); return getThis();
} }
@Override
public T setQueryParameterValidation(boolean enabled) {
delegate.setQueryParameterValidation( enabled );
return getThis();
}
@Override @Override
public T connectionHandlingMode(PhysicalConnectionHandlingMode mode) { public T connectionHandlingMode(PhysicalConnectionHandlingMode mode) {
delegate.connectionHandlingMode( mode ); delegate.connectionHandlingMode( mode );

View File

@ -327,11 +327,6 @@ public class SessionDelegatorBaseImpl implements SessionImplementor {
return delegate.isAutoCloseSessionEnabled(); return delegate.isAutoCloseSessionEnabled();
} }
@Override
public boolean isQueryParametersValidationEnabled() {
return delegate.isQueryParametersValidationEnabled();
}
@Override @Override
public boolean shouldAutoJoinTransaction() { public boolean shouldAutoJoinTransaction() {
return delegate.shouldAutoJoinTransaction(); return delegate.shouldAutoJoinTransaction();

View File

@ -396,10 +396,6 @@ public interface SharedSessionContractImplementor
boolean isAutoCloseSessionEnabled(); boolean isAutoCloseSessionEnabled();
default boolean isQueryParametersValidationEnabled(){
return getFactory().getSessionFactoryOptions().isQueryParametersValidationEnabled();
}
/** /**
* Get the load query influencers associated with this session. * Get the load query influencers associated with this session.
* *

View File

@ -72,6 +72,4 @@ public interface SessionCreationOptions {
AfterCompletionAction getAfterCompletionAction(); AfterCompletionAction getAfterCompletionAction();
ManagedFlushChecker getManagedFlushChecker(); ManagedFlushChecker getManagedFlushChecker();
boolean isQueryParametersValidationEnabled();
} }

View File

@ -1170,7 +1170,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
private boolean autoClear; private boolean autoClear;
private String tenantIdentifier; private String tenantIdentifier;
private TimeZone jdbcTimeZone; private TimeZone jdbcTimeZone;
private boolean queryParametersValidationEnabled;
private boolean explicitNoInterceptor; private boolean explicitNoInterceptor;
// Lazy: defaults can be built by invoking the builder in fastSessionServices.defaultSessionEventListeners // Lazy: defaults can be built by invoking the builder in fastSessionServices.defaultSessionEventListeners
@ -1195,7 +1194,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier(); tenantIdentifier = currentTenantIdentifierResolver.resolveCurrentTenantIdentifier();
} }
this.jdbcTimeZone = sessionFactoryOptions.getJdbcTimeZone(); this.jdbcTimeZone = sessionFactoryOptions.getJdbcTimeZone();
this.queryParametersValidationEnabled = sessionFactoryOptions.isQueryParametersValidationEnabled();
} }
@ -1228,11 +1226,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
: null; : null;
} }
@Override
public boolean isQueryParametersValidationEnabled() {
return this.queryParametersValidationEnabled;
}
@Override @Override
public boolean shouldAutoJoinTransactions() { public boolean shouldAutoJoinTransactions() {
return autoJoinTransactions; return autoJoinTransactions;
@ -1419,19 +1412,12 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
jdbcTimeZone = timeZone; jdbcTimeZone = timeZone;
return (T) this; return (T) this;
} }
@Override
public T setQueryParameterValidation(boolean enabled) {
queryParametersValidationEnabled = enabled;
return (T) this;
}
} }
public static class StatelessSessionBuilderImpl implements StatelessSessionBuilder, SessionCreationOptions { public static class StatelessSessionBuilderImpl implements StatelessSessionBuilder, SessionCreationOptions {
private final SessionFactoryImpl sessionFactory; private final SessionFactoryImpl sessionFactory;
private Connection connection; private Connection connection;
private String tenantIdentifier; private String tenantIdentifier;
private boolean queryParametersValidationEnabled;
public StatelessSessionBuilderImpl(SessionFactoryImpl sessionFactory) { public StatelessSessionBuilderImpl(SessionFactoryImpl sessionFactory) {
this.sessionFactory = sessionFactory; this.sessionFactory = sessionFactory;
@ -1440,7 +1426,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
if ( tenantIdentifierResolver != null ) { if ( tenantIdentifierResolver != null ) {
tenantIdentifier = tenantIdentifierResolver.resolveCurrentTenantIdentifier(); tenantIdentifier = tenantIdentifierResolver.resolveCurrentTenantIdentifier();
} }
queryParametersValidationEnabled = sessionFactory.getSessionFactoryOptions().isQueryParametersValidationEnabled();
} }
@Override @Override
@ -1535,17 +1520,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
public ManagedFlushChecker getManagedFlushChecker() { public ManagedFlushChecker getManagedFlushChecker() {
return null; return null;
} }
@Override
public boolean isQueryParametersValidationEnabled() {
return queryParametersValidationEnabled;
}
@Override
public StatelessSessionBuilder setQueryParameterValidation(boolean enabled) {
queryParametersValidationEnabled = enabled;
return this;
}
} }
@Override @Override

View File

@ -183,7 +183,6 @@ public class SessionImpl
private boolean autoClear; private boolean autoClear;
private boolean autoClose; private boolean autoClose;
private boolean queryParametersValidationEnabled;
private transient int dontFlushFromFind; private transient int dontFlushFromFind;
@ -201,7 +200,6 @@ public class SessionImpl
this.autoClear = options.shouldAutoClear(); this.autoClear = options.shouldAutoClear();
this.autoClose = options.shouldAutoClose(); this.autoClose = options.shouldAutoClose();
this.queryParametersValidationEnabled = options.isQueryParametersValidationEnabled();
if ( options instanceof SharedSessionCreationOptions ) { if ( options instanceof SharedSessionCreationOptions ) {
final SharedSessionCreationOptions sharedOptions = (SharedSessionCreationOptions) options; final SharedSessionCreationOptions sharedOptions = (SharedSessionCreationOptions) options;
@ -431,11 +429,6 @@ public class SessionImpl
return autoClose; return autoClose;
} }
@Override
public boolean isQueryParametersValidationEnabled() {
return queryParametersValidationEnabled;
}
@Override @Override
public boolean isOpen() { public boolean isOpen() {
checkSessionFactoryOpen(); checkSessionFactoryOpen();
@ -2067,11 +2060,6 @@ public class SessionImpl
session.getActionQueue().getTransactionCompletionProcesses() : session.getActionQueue().getTransactionCompletionProcesses() :
null; null;
} }
@Override
public boolean isQueryParametersValidationEnabled() {
return session.isQueryParametersValidationEnabled();
}
} }
private class LockRequestImpl implements LockRequest { private class LockRequestImpl implements LockRequest {

View File

@ -23,6 +23,6 @@ public class ProcedureParameterBindingImpl<T>
public ProcedureParameterBindingImpl( public ProcedureParameterBindingImpl(
ProcedureParameterImplementor<T> queryParameter, ProcedureParameterImplementor<T> queryParameter,
SessionFactoryImplementor sessionFactory) { SessionFactoryImplementor sessionFactory) {
super( queryParameter, sessionFactory, true ); super( queryParameter, sessionFactory );
} }
} }

View File

@ -33,7 +33,6 @@ import jakarta.persistence.TemporalType;
public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, JavaType.CoercionContext { public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, JavaType.CoercionContext {
private final QueryParameter<T> queryParameter; private final QueryParameter<T> queryParameter;
private final SessionFactoryImplementor sessionFactory; private final SessionFactoryImplementor sessionFactory;
private final boolean isBindingValidationRequired;
private boolean isBound; private boolean isBound;
private boolean isMultiValued; private boolean isMultiValued;
@ -50,11 +49,9 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
*/ */
protected QueryParameterBindingImpl( protected QueryParameterBindingImpl(
QueryParameter<T> queryParameter, QueryParameter<T> queryParameter,
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory) {
boolean isBindingValidationRequired) {
this.queryParameter = queryParameter; this.queryParameter = queryParameter;
this.sessionFactory = sessionFactory; this.sessionFactory = sessionFactory;
this.isBindingValidationRequired = isBindingValidationRequired;
this.bindType = queryParameter.getHibernateType(); this.bindType = queryParameter.getHibernateType();
} }
@ -64,11 +61,9 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
public QueryParameterBindingImpl( public QueryParameterBindingImpl(
QueryParameter<T> queryParameter, QueryParameter<T> queryParameter,
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
BindableType<T> bindType, BindableType<T> bindType) {
boolean isBindingValidationRequired) {
this.queryParameter = queryParameter; this.queryParameter = queryParameter;
this.sessionFactory = sessionFactory; this.sessionFactory = sessionFactory;
this.isBindingValidationRequired = isBindingValidationRequired;
this.bindType = bindType; this.bindType = bindType;
} }
@ -132,9 +127,7 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
} }
} }
if ( isBindingValidationRequired ) { validate( value );
validate( value );
}
if ( resolveJdbcTypeIfNecessary && bindType == null && value == null ) { if ( resolveJdbcTypeIfNecessary && bindType == null && value == null ) {
bindType = getTypeConfiguration().getBasicTypeRegistry().getRegisteredType( "null" ); bindType = getTypeConfiguration().getBasicTypeRegistry().getRegisteredType( "null" );
@ -203,9 +196,7 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
value = coerce( value, queryParameter.getHibernateType() ); value = coerce( value, queryParameter.getHibernateType() );
} }
if ( isBindingValidationRequired ) { validate( value, clarifiedType );
validate( value, clarifiedType );
}
bindValue( value ); bindValue( value );
} }
@ -242,9 +233,7 @@ public class QueryParameterBindingImpl<T> implements QueryParameterBinding<T>, J
} }
} }
if ( isBindingValidationRequired ) { validate( value, temporalTypePrecision );
validate( value, temporalTypePrecision );
}
bindValue( value ); bindValue( value );
setExplicitTemporalPrecision( temporalTypePrecision ); setExplicitTemporalPrecision( temporalTypePrecision );

View File

@ -41,57 +41,34 @@ import org.hibernate.type.spi.TypeConfiguration;
public class QueryParameterBindingsImpl implements QueryParameterBindings { public class QueryParameterBindingsImpl implements QueryParameterBindings {
private final SessionFactoryImplementor sessionFactory; private final SessionFactoryImplementor sessionFactory;
private final ParameterMetadataImplementor parameterMetadata; private final ParameterMetadataImplementor parameterMetadata;
private final boolean queryParametersValidationEnabled;
private Map<QueryParameter<?>, QueryParameterBinding<?>> parameterBindingMap; private Map<QueryParameter<?>, QueryParameterBinding<?>> parameterBindingMap;
/** /**
* Constructs a QueryParameterBindings based on the passed information * Constructs a QueryParameterBindings based on the passed information
*
* @apiNote Calls {@link #from(ParameterMetadataImplementor,SessionFactoryImplementor,boolean)}
* using {@link org.hibernate.boot.spi.SessionFactoryOptions#isQueryParametersValidationEnabled}
* as `queryParametersValidationEnabled`
*/ */
public static QueryParameterBindingsImpl from( public static QueryParameterBindingsImpl from(
ParameterMetadataImplementor parameterMetadata, ParameterMetadataImplementor parameterMetadata,
SessionFactoryImplementor sessionFactory) { SessionFactoryImplementor sessionFactory) {
return from(
parameterMetadata,
sessionFactory,
sessionFactory.getSessionFactoryOptions().isQueryParametersValidationEnabled()
);
}
/**
* Constructs a QueryParameterBindings based on the passed information
*/
public static QueryParameterBindingsImpl from(
ParameterMetadataImplementor parameterMetadata,
SessionFactoryImplementor sessionFactory,
boolean queryParametersValidationEnabled) {
if ( parameterMetadata == null ) { if ( parameterMetadata == null ) {
throw new QueryParameterException( "Query parameter metadata cannot be null" ); throw new QueryParameterException( "Query parameter metadata cannot be null" );
} }
return new QueryParameterBindingsImpl( return new QueryParameterBindingsImpl(
sessionFactory, sessionFactory,
parameterMetadata, parameterMetadata
queryParametersValidationEnabled
); );
} }
private QueryParameterBindingsImpl( private QueryParameterBindingsImpl(
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
ParameterMetadataImplementor parameterMetadata, ParameterMetadataImplementor parameterMetadata) {
boolean queryParametersValidationEnabled) {
this.sessionFactory = sessionFactory; this.sessionFactory = sessionFactory;
this.parameterMetadata = parameterMetadata; this.parameterMetadata = parameterMetadata;
this.queryParametersValidationEnabled = queryParametersValidationEnabled;
this.parameterBindingMap = new ConcurrentHashMap<>( parameterMetadata.getParameterCount() ); this.parameterBindingMap = new ConcurrentHashMap<>( parameterMetadata.getParameterCount() );
} }
@SuppressWarnings({"WeakerAccess" })
protected <T> QueryParameterBinding<T> makeBinding(QueryParameterImplementor<T> queryParameter) { protected <T> QueryParameterBinding<T> makeBinding(QueryParameterImplementor<T> queryParameter) {
if ( parameterBindingMap == null ) { if ( parameterBindingMap == null ) {
parameterBindingMap = new IdentityHashMap<>(); parameterBindingMap = new IdentityHashMap<>();
@ -109,8 +86,7 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
final QueryParameterBinding<T> binding = new QueryParameterBindingImpl<>( final QueryParameterBinding<T> binding = new QueryParameterBindingImpl<>(
queryParameter, queryParameter,
sessionFactory, sessionFactory,
parameterMetadata.getInferredParameterType( queryParameter ), parameterMetadata.getInferredParameterType( queryParameter )
queryParametersValidationEnabled
); );
parameterBindingMap.put( queryParameter, binding ); parameterBindingMap.put( queryParameter, binding );

View File

@ -190,11 +190,7 @@ public class NativeQueryImpl<R>
this.sqlString = parameterInterpretation.getAdjustedSqlString(); this.sqlString = parameterInterpretation.getAdjustedSqlString();
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session ); this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences(); this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences();
this.parameterBindings = QueryParameterBindingsImpl.from( this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, session.getFactory() );
parameterMetadata,
session.getFactory(),
session.isQueryParametersValidationEnabled()
);
this.querySpaces = new HashSet<>(); this.querySpaces = new HashSet<>();
this.resultSetMapping = resultSetMappingCreator.get(); this.resultSetMapping = resultSetMappingCreator.get();
@ -327,11 +323,7 @@ public class NativeQueryImpl<R>
this.sqlString = parameterInterpretation.getAdjustedSqlString(); this.sqlString = parameterInterpretation.getAdjustedSqlString();
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session ); this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences(); this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences();
this.parameterBindings = QueryParameterBindingsImpl.from( this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, session.getFactory() );
parameterMetadata,
session.getFactory(),
session.isQueryParametersValidationEnabled()
);
this.querySpaces = new HashSet<>(); this.querySpaces = new HashSet<>();
this.resultSetMapping = new ResultSetMappingImpl( resultSetMappingMemento.getName() ); this.resultSetMapping = new ResultSetMappingImpl( resultSetMappingMemento.getName() );
@ -386,11 +378,7 @@ public class NativeQueryImpl<R>
this.sqlString = parameterInterpretation.getAdjustedSqlString(); this.sqlString = parameterInterpretation.getAdjustedSqlString();
this.parameterMetadata = parameterInterpretation.toParameterMetadata( session ); this.parameterMetadata = parameterInterpretation.toParameterMetadata( session );
this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences(); this.parameterOccurrences = parameterInterpretation.getOrderedParameterOccurrences();
this.parameterBindings = QueryParameterBindingsImpl.from( this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, session.getFactory() );
parameterMetadata,
session.getFactory(),
session.isQueryParametersValidationEnabled()
);
this.resultSetMapping = new ResultSetMappingImpl( sqlString, true ); this.resultSetMapping = new ResultSetMappingImpl( sqlString, true );
this.resultMappingSuppliedToCtor = false; this.resultMappingSuppliedToCtor = false;

View File

@ -159,11 +159,7 @@ public class QuerySqmImpl<R>
this.domainParameterXref = hqlInterpretation.getDomainParameterXref(); this.domainParameterXref = hqlInterpretation.getDomainParameterXref();
this.parameterMetadata = hqlInterpretation.getParameterMetadata(); this.parameterMetadata = hqlInterpretation.getParameterMetadata();
this.parameterBindings = QueryParameterBindingsImpl.from( this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
parameterMetadata,
producer.getFactory(),
producer.isQueryParametersValidationEnabled()
);
applyOptions( memento ); applyOptions( memento );
} }
@ -224,11 +220,7 @@ public class QuerySqmImpl<R>
this.parameterMetadata = hqlInterpretation.getParameterMetadata(); this.parameterMetadata = hqlInterpretation.getParameterMetadata();
this.domainParameterXref = hqlInterpretation.getDomainParameterXref(); this.domainParameterXref = hqlInterpretation.getDomainParameterXref();
this.parameterBindings = QueryParameterBindingsImpl.from( this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
parameterMetadata,
producer.getFactory(),
producer.isQueryParametersValidationEnabled()
);
} }
/** /**
@ -275,11 +267,8 @@ public class QuerySqmImpl<R>
this.parameterMetadata = new ParameterMetadataImpl( domainParameterXref.getQueryParameters() ); this.parameterMetadata = new ParameterMetadataImpl( domainParameterXref.getQueryParameters() );
} }
this.parameterBindings = QueryParameterBindingsImpl.from( this.parameterBindings = QueryParameterBindingsImpl.from( parameterMetadata, producer.getFactory() );
parameterMetadata,
producer.getFactory(),
producer.isQueryParametersValidationEnabled()
);
// Parameters might be created through HibernateCriteriaBuilder.value which we need to bind here // Parameters might be created through HibernateCriteriaBuilder.value which we need to bind here
for ( SqmParameter<?> sqmParameter : this.domainParameterXref.getParameterResolutions().getSqmParameters() ) { for ( SqmParameter<?> sqmParameter : this.domainParameterXref.getParameterResolutions().getSqmParameters() ) {
if ( sqmParameter instanceof SqmJpaCriteriaParameterWrapper<?> ) { if ( sqmParameter instanceof SqmJpaCriteriaParameterWrapper<?> ) {

View File

@ -59,20 +59,6 @@ public class QueryParametersValidationTest extends BaseEntityManagerFunctionalTe
} }
} }
@Test
@TestForIssue(jiraKey = "HHH-11579")
public void setParameterWithWrongTypeShouldNotThrowIllegalArgumentExceptionWhenValidationIsDisabled() {
final SessionFactory sessionFactory = entityManagerFactory().unwrap( SessionFactory.class );
final Session session = sessionFactory.withOptions().setQueryParameterValidation( false ).openSession();
try {
session.createQuery( "select e from TestEntity e where e.id = :id" ).setParameter( "id", 1 );
}
finally {
session.close();
sessionFactory.close();
}
}
@Test @Test
public void setParameterWithCorrectTypeShouldNotThrowIllegalArgumentException() { public void setParameterWithCorrectTypeShouldNotThrowIllegalArgumentException() {
final EntityManager entityManager = entityManagerFactory().createEntityManager(); final EntityManager entityManager = entityManagerFactory().createEntityManager();

View File

@ -27,8 +27,7 @@ import org.junit.jupiter.api.Test;
@Jpa( @Jpa(
annotatedClasses = { annotatedClasses = {
QueryParametersWithDisabledValidationTest.TestEntity.class QueryParametersWithDisabledValidationTest.TestEntity.class
}, }
integrationSettings = { @Setting(name = AvailableSettings.VALIDATE_QUERY_PARAMETERS, value = "false") }
) )
public class QueryParametersWithDisabledValidationTest { public class QueryParametersWithDisabledValidationTest {