Skip to content

Commit

Permalink
HHH-18709 Also apply inferrable types to jpa criteria parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mbladel committed Nov 21, 2024
1 parent 07b54de commit e2e9128
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.hibernate.query.sqm.tree.expression.JpaCriteriaParameter;
import org.hibernate.query.sqm.tree.expression.SqmJpaCriteriaParameterWrapper;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.expression.ValueBindJpaCriteriaParameter;
import org.hibernate.query.sqm.tree.from.SqmRoot;
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
import org.hibernate.query.sqm.tree.insert.SqmInsertValuesStatement;
Expand Down Expand Up @@ -245,9 +246,8 @@ public QuerySqmImpl(
private <T> void bindCriteriaParameter(SqmJpaCriteriaParameterWrapper<T> sqmParameter) {
final JpaCriteriaParameter<T> jpaCriteriaParameter = sqmParameter.getJpaCriteriaParameter();
final T value = jpaCriteriaParameter.getValue();
// We don't set a null value, unless the type is also null which
// is the case when using HibernateCriteriaBuilder.value
if ( value != null || jpaCriteriaParameter.getNodeType() == null ) {
// We don't set a null value, unless using HibernateCriteriaBuilder.value
if ( value != null || jpaCriteriaParameter instanceof ValueBindJpaCriteriaParameter<?> ) {
// Use the anticipated type for binding the value if possible
getQueryParameterBindings().getBinding( jpaCriteriaParameter )
.setBindValue( value, jpaCriteriaParameter.getAnticipatedType() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class AbstractSqmParameter<T> extends AbstractSqmExpression<T> i

public AbstractSqmParameter(
boolean canBeMultiValued,
SqmExpressible<T> inherentType,
SqmExpressible<? super T> inherentType,
NodeBuilder nodeBuilder) {
super( inherentType, nodeBuilder );
this.canBeMultiValued = canBeMultiValued;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,22 @@
* @author Steve Ebersole
*/
public class JpaCriteriaParameter<T>
extends AbstractSqmExpression<T>
implements SqmParameter<T>, QueryParameterImplementor<T> {
extends AbstractSqmParameter<T>
implements QueryParameterImplementor<T> {
private final String name;
private boolean allowsMultiValuedBinding;

public JpaCriteriaParameter(
String name,
BindableType<? super T> type,
boolean allowsMultiValuedBinding,
NodeBuilder nodeBuilder) {
super( toSqmType( type, nodeBuilder ), nodeBuilder );
super( allowsMultiValuedBinding, toSqmType( type, nodeBuilder ), nodeBuilder );
this.name = name;
this.allowsMultiValuedBinding = allowsMultiValuedBinding;
}

protected JpaCriteriaParameter(JpaCriteriaParameter<T> original) {
super( original.getNodeType(), original.nodeBuilder() );
super( original.allowMultiValuedBinding(), original.getNodeType(), original.nodeBuilder() );
this.name = original.name;
this.allowsMultiValuedBinding = original.allowsMultiValuedBinding;
}

private static <T> SqmExpressible<T> toSqmType(BindableType<T> type, NodeBuilder nodeBuilder) {
Expand Down Expand Up @@ -84,17 +81,7 @@ public Integer getTupleLength() {

@Override
public boolean allowsMultiValuedBinding() {
return allowsMultiValuedBinding;
}

@Override
public void disallowMultiValuedBinding() {
allowsMultiValuedBinding = false;
}

@Override
public boolean allowMultiValuedBinding() {
return allowsMultiValuedBinding();
return allowMultiValuedBinding();
}

@Override
Expand Down Expand Up @@ -129,11 +116,6 @@ public Class<T> getParameterType() {
return nodeType == null ? null : nodeType.getExpressibleJavaType().getJavaTypeClass();
}

@Override
protected void internalApplyInferableType(SqmExpressible<?> newType) {
super.internalApplyInferableType( newType );
}

@Override
public <X> X accept(SemanticQueryWalker<X> walker) {
return walker.visitJpaCriteriaParameter( this );
Expand Down

0 comments on commit e2e9128

Please sign in to comment.