HHH-18201 - Do not make any assumptions when LHS operand of addition/subtraction is not known
and RHS operand is of duration type. Allowed combinations are templral +/- duration duration +/- duration nut final decision can be only make knowing full context
This commit is contained in:
parent
ca581e74f4
commit
edbece8125
|
@ -14,6 +14,12 @@ import org.hibernate.query.sqm.SqmExpressible;
|
||||||
import org.hibernate.query.sqm.tree.SqmCopyContext;
|
import org.hibernate.query.sqm.tree.SqmCopyContext;
|
||||||
import org.hibernate.query.sqm.tree.select.SqmSelectableNode;
|
import org.hibernate.query.sqm.tree.select.SqmSelectableNode;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import static org.hibernate.query.sqm.BinaryArithmeticOperator.ADD;
|
||||||
|
import static org.hibernate.query.sqm.BinaryArithmeticOperator.SUBTRACT;
|
||||||
|
import static org.hibernate.type.spi.TypeConfiguration.isDuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +48,10 @@ public class SqmBinaryArithmetic<T> extends AbstractSqmExpression<T> implements
|
||||||
this.operator = operator;
|
this.operator = operator;
|
||||||
this.rhsOperand = rhsOperand;
|
this.rhsOperand = rhsOperand;
|
||||||
|
|
||||||
|
if ( lhsOperand.getExpressible() == null && isDuration( rhsOperand.getExpressible() ) &&
|
||||||
|
( operator == ADD || operator == SUBTRACT ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.lhsOperand.applyInferableType( rhsOperand.getNodeType() );
|
this.lhsOperand.applyInferableType( rhsOperand.getNodeType() );
|
||||||
this.rhsOperand.applyInferableType( lhsOperand.getNodeType() );
|
this.rhsOperand.applyInferableType( lhsOperand.getNodeType() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -682,9 +682,15 @@ public class TypeConfiguration implements SessionFactoryObserver, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( isDuration( secondType ) ) {
|
else if ( isDuration( secondType ) ) {
|
||||||
// it's either addition/subtraction of durations
|
// if firstType is not known, and operator is
|
||||||
|
// addition/subtraction, then this can be
|
||||||
|
// either addition/subtraction of duration
|
||||||
|
// to/from temporal or addition/subtraction of
|
||||||
|
// durations in this case we shall return null;
|
||||||
|
// otherwise, it's either addition/subtraction of durations
|
||||||
// or prefix scalar multiplication of a duration
|
// or prefix scalar multiplication of a duration
|
||||||
return secondType;
|
// return secondType;
|
||||||
|
return firstType == null ? null : secondType;
|
||||||
}
|
}
|
||||||
else if ( firstType==null && getSqlTemporalType( secondType ) != null ) {
|
else if ( firstType==null && getSqlTemporalType( secondType ) != null ) {
|
||||||
// subtraction of a date or timestamp from a
|
// subtraction of a date or timestamp from a
|
||||||
|
|
Loading…
Reference in New Issue