From dc272128a129612c11c15e1cbdc65083d56a814e Mon Sep 17 00:00:00 2001 From: Arturas Sirvinskas Date: Tue, 6 Mar 2018 17:31:53 +0000 Subject: [PATCH] HHH-7119 - Hibernate filter's parameters are not populated when an entity's Collection is populated using a fetch mode of subselect --- .../hibernate/engine/spi/QueryParameters.java | 19 +++++++++++++++++-- .../DynamicFilterParameterSpecification.java | 9 +++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java index 36bbb2e116..a942be7c1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/QueryParameters.java @@ -70,7 +70,7 @@ public final class QueryParameters { private String processedSQL; private Type[] processedPositionalParameterTypes; private Object[] processedPositionalParameterValues; - + private HQLQueryPlan queryPlan; public QueryParameters() { @@ -91,7 +91,6 @@ public final class QueryParameters { this.optionalObject = optionalObject; this.optionalId = optionalObjectId; this.optionalEntityName = optionalEntityName; - } public QueryParameters( @@ -665,4 +664,20 @@ public final class QueryParameters { public void setQueryPlan(HQLQueryPlan queryPlan) { this.queryPlan = queryPlan; } + + public void bindDynamicParameter(Type paramType, Object paramValue) { + if(processedPositionalParameterTypes != null) { + int length = processedPositionalParameterTypes.length; + Type[] types = new Type[length + 1]; + Object[] values = new Object[length + 1]; + for ( int i = 0; i < length; i++ ) { + types[i] = processedPositionalParameterTypes[i]; + values[i] = processedPositionalParameterValues[i]; + } + types[length] = paramType; + values[length] = paramValue; + processedPositionalParameterTypes = types; + processedPositionalParameterValues = values; + } + } } diff --git a/hibernate-core/src/main/java/org/hibernate/param/DynamicFilterParameterSpecification.java b/hibernate-core/src/main/java/org/hibernate/param/DynamicFilterParameterSpecification.java index 916d45efd3..def45bdf99 100644 --- a/hibernate-core/src/main/java/org/hibernate/param/DynamicFilterParameterSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/param/DynamicFilterParameterSpecification.java @@ -50,17 +50,22 @@ public class DynamicFilterParameterSpecification implements ParameterSpecificati SharedSessionContractImplementor session, int start) throws SQLException { final int columnSpan = definedParameterType.getColumnSpan( session.getFactory() ); - final Object value = session.getLoadQueryInfluencers().getFilterParameterValue( filterName + '.' + parameterName ); + final String fullParamName = filterName + '.' + parameterName; + final Object value = session.getLoadQueryInfluencers().getFilterParameterValue(fullParamName); + final Type type = session.getLoadQueryInfluencers().getFilterParameterType(fullParamName); if ( Collection.class.isInstance( value ) ) { int positions = 0; Iterator itr = ( ( Collection ) value ).iterator(); while ( itr.hasNext() ) { - definedParameterType.nullSafeSet( statement, itr.next(), start + positions, session ); + Object next = itr.next(); + qp.bindDynamicParameter( type, next ); + definedParameterType.nullSafeSet( statement, next, start + positions, session ); positions += columnSpan; } return positions; } else { + qp.bindDynamicParameter(type, value); definedParameterType.nullSafeSet( statement, value, start, session ); return columnSpan; }