Skip to content

Commit 61586d9

Browse files
committed
HHH-15256 HQL Query with left join throws NPE when using :param IS NULL
1 parent 7477771 commit 61586d9

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@
369369
import org.hibernate.sql.results.internal.StandardEntityGraphTraversalStateImpl;
370370
import org.hibernate.type.BasicType;
371371
import org.hibernate.type.JavaObjectType;
372+
import org.hibernate.type.NullType;
372373
import org.hibernate.type.SqlTypes;
373374
import org.hibernate.type.descriptor.java.BasicJavaType;
374375
import org.hibernate.type.descriptor.java.EnumJavaType;
@@ -383,6 +384,8 @@
383384
import org.jboss.logging.Logger;
384385

385386
import jakarta.persistence.TemporalType;
387+
import jakarta.persistence.metamodel.SingularAttribute;
388+
import jakarta.persistence.metamodel.Type;
386389

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

4887-
if ( basicTypeForJavaType == null && paramSqmType instanceof EntityDomainType ) {
4888-
final SimpleDomainType idType = ( (EntityDomainType) paramSqmType ).getIdType();
4889-
if ( idType != null ) {
4890-
return getTypeConfiguration().getBasicTypeForJavaType(
4891-
idType.getExpressibleJavaType().getJavaTypeClass() );
4890+
if ( basicTypeForJavaType == null ) {
4891+
if ( paramSqmType instanceof EntityDomainType ) {
4892+
return getIdType( (EntityDomainType) paramSqmType );
4893+
}
4894+
else if ( paramSqmType instanceof SingularAttribute ) {
4895+
final Type type = ( (SingularAttribute) paramSqmType ).getType();
4896+
if ( type instanceof EntityDomainType ) {
4897+
return getIdType( (EntityDomainType) type );
4898+
}
48924899
}
48934900
}
48944901

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

4908+
private BasicType getIdType(EntityDomainType entityDomainType) {
4909+
final SimpleDomainType idType = entityDomainType.getIdType();
4910+
if ( idType != null ) {
4911+
return getTypeConfiguration().getBasicTypeForJavaType(
4912+
idType.getExpressibleJavaType().getJavaTypeClass() );
4913+
}
4914+
return null;
4915+
}
4916+
49014917
private void resolveSqmParameter(
49024918
SqmParameter<?> expression,
49034919
MappingModelExpressible<?> valueMapping,
@@ -4958,6 +4974,10 @@ else if ( bindValue instanceof BigDecimal ) {
49584974
}
49594975
}
49604976
if ( sqlTypedMapping == null ) {
4977+
if ( bindable == null ) {
4978+
throw new ConversionException(
4979+
"Could not determine neither the SqlTypedMapping nor the Bindable value for SqmParameter: " + expression );
4980+
}
49614981
bindable.forEachJdbcType(
49624982
(index, jdbcMapping) -> jdbcParameterConsumer.accept(
49634983
index,

0 commit comments

Comments
 (0)