Skip to content

Commit 1237977

Browse files
committed
HHH-15498 Delete Query fails to determine the ValueMapping for SqmParameter
1 parent c2fab87 commit 1237977

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5181,13 +5181,21 @@ else if ( paramType instanceof EntityDomainType ) {
51815181

51825182
if ( paramSqmType instanceof SqmPathSource<?> || paramSqmType instanceof BasicDomainType<?> ) {
51835183
// Try to infer the value mapping since the other side apparently is a path source
5184-
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
5185-
if ( inferredValueMapping != null ) {
5186-
return resolveInferredValueMappingForParameter( inferredValueMapping );
5184+
final MappingModelExpressible<?> inferredMapping = resolveInferredType();
5185+
if ( inferredMapping != null ) {
5186+
if ( inferredMapping instanceof PluralAttributeMapping ) {
5187+
return resolveInferredValueMappingForParameter( ( (PluralAttributeMapping) inferredMapping ).getElementDescriptor() );
5188+
}
5189+
else if ( !( inferredMapping instanceof JavaObjectType ) ) {
5190+
// Do not report back the "object type" as inferred type and instead try to rely on the paramSqmType.getExpressibleJavaType()
5191+
return resolveInferredValueMappingForParameter( inferredMapping );
5192+
}
51875193
}
51885194

5195+
final Class<?> parameterJavaType = paramSqmType.getExpressibleJavaType().getJavaTypeClass();
5196+
51895197
final BasicType<?> basicTypeForJavaType = getTypeConfiguration().getBasicTypeForJavaType(
5190-
paramSqmType.getExpressibleJavaType().getJavaTypeClass()
5198+
parameterJavaType
51915199
);
51925200

51935201
if ( basicTypeForJavaType == null ) {
@@ -5200,11 +5208,15 @@ else if ( paramSqmType instanceof SingularAttribute ) {
52005208
return resolveEntityPersister( (EntityDomainType<?>) type );
52015209
}
52025210
}
5211+
else if ( parameterJavaType.isEnum() ) {
5212+
//inferredMapping is JavaObjectType and we cannot deduct the t
5213+
if ( inferredMapping != null ) {
5214+
return inferredMapping;
5215+
}
5216+
}
52035217
}
5204-
52055218
return basicTypeForJavaType;
52065219
}
5207-
52085220
throw new ConversionException( "Could not determine ValueMapping for SqmParameter: " + sqmParameter );
52095221
}
52105222

@@ -6681,7 +6693,7 @@ public LikePredicate visitLikePredicate(SqmLikePredicate predicate) {
66816693
@Override
66826694
public NullnessPredicate visitIsNullPredicate(SqmNullnessPredicate predicate) {
66836695
return new NullnessPredicate(
6684-
(Expression) predicate.getExpression().accept( this ),
6696+
(Expression) visitWithInferredType( predicate.getExpression(), () -> basicType( Object.class )),
66856697
predicate.isNegated(),
66866698
getBooleanType()
66876699
);

0 commit comments

Comments
 (0)