Skip to content

Commit

Permalink
HHH-15256 HQL Query with left join throws NPE when using :param IS NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
dreab8 committed May 16, 2022
1 parent 7477771 commit 61586d9
Showing 1 changed file with 25 additions and 5 deletions.
Expand Up @@ -369,6 +369,7 @@
import org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl;
import org.hibernate.type.BasicType;
import org.hibernate.type.JavaObjectType;
import org.hibernate.type.NullType;
import org.hibernate.type.SqlTypes;
import org.hibernate.type.descriptor.java.BasicJavaType;
import org.hibernate.type.descriptor.java.EnumJavaType;
Expand All @@ -383,6 +384,8 @@
import org.jboss.logging.Logger;

import jakarta.persistence.TemporalType;
import jakarta.persistence.metamodel.SingularAttribute;
import jakarta.persistence.metamodel.Type;

import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
import static org.hibernate.query.sqm.BinaryArithmeticOperator.ADD;
Expand Down Expand Up @@ -4884,11 +4887,15 @@ else if ( paramType instanceof EntityDomainType ) {
paramSqmType.getExpressibleJavaType().getJavaTypeClass()
);

if ( basicTypeForJavaType == null && paramSqmType instanceof EntityDomainType ) {
final SimpleDomainType idType = ( (EntityDomainType) paramSqmType ).getIdType();
if ( idType != null ) {
return getTypeConfiguration().getBasicTypeForJavaType(
idType.getExpressibleJavaType().getJavaTypeClass() );
if ( basicTypeForJavaType == null ) {
if ( paramSqmType instanceof EntityDomainType ) {
return getIdType( (EntityDomainType) paramSqmType );
}
else if ( paramSqmType instanceof SingularAttribute ) {
final Type type = ( (SingularAttribute) paramSqmType ).getType();
if ( type instanceof EntityDomainType ) {
return getIdType( (EntityDomainType) type );
}
}
}

Expand All @@ -4898,6 +4905,15 @@ else if ( paramType instanceof EntityDomainType ) {
throw new ConversionException( "Could not determine ValueMapping for SqmParameter: " + sqmParameter );
}

private BasicType getIdType(EntityDomainType entityDomainType) {
final SimpleDomainType idType = entityDomainType.getIdType();
if ( idType != null ) {
return getTypeConfiguration().getBasicTypeForJavaType(
idType.getExpressibleJavaType().getJavaTypeClass() );
}
return null;
}

private void resolveSqmParameter(
SqmParameter<?> expression,
MappingModelExpressible<?> valueMapping,
Expand Down Expand Up @@ -4958,6 +4974,10 @@ else if ( bindValue instanceof BigDecimal ) {
}
}
if ( sqlTypedMapping == null ) {
if ( bindable == null ) {
throw new ConversionException(
"Could not determine neither the SqlTypedMapping nor the Bindable value for SqmParameter: " + expression );
}
bindable.forEachJdbcType(
(index, jdbcMapping) -> jdbcParameterConsumer.accept(
index,
Expand Down

0 comments on commit 61586d9

Please sign in to comment.