HHH-7119 - Hibernate filter's parameters are not populated when an entity's Collection is populated using a fetch mode of subselect

This commit is contained in:
Arturas Sirvinskas 2018-03-06 17:31:53 +00:00 committed by Andrea Boriero
parent 020dd7f9da
commit dc272128a1
2 changed files with 24 additions and 4 deletions

View File

@ -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;
}
}
}

View File

@ -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;
}