{"record":{"id":"70629da7d4c83fcb","repo":"hibernate/hibernate-orm","slug":"could-not-determine-valuemapping-for-sqmexpression","errorCode":null,"errorMessage":"Could not determine ValueMapping for SqmExpression: {}","messagePattern":"Could not determine ValueMapping for SqmExpression: (.+?)","errorType":"exception","errorClass":"ConversionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java","lineNumber":6524,"sourceCode":"\t\t}\n\n\n\t\tfinal var valueMapping =\n\t\t\t\tdomainModel.resolveMappingExpressible( nodeType, fromClauseIndex::getTableGroup );\n\n\t\tif ( valueMapping == null ) {\n\t\t\tfinal var mappingModelExpressible = resolveInferredType();\n\t\t\tif ( mappingModelExpressible != null ) {\n\t\t\t\treturn mappingModelExpressible;\n\t\t\t}\n\t\t}\n\n\t\tif ( valueMapping == null ) {\n\t\t\t// For literals, it is totally possible that we can't figure out a mapping type\n\t\t\tif ( sqmExpression instanceof SqmLiteral<?> ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tthrow new ConversionException( \"Could not determine ValueMapping for SqmExpression: \" + sqmExpression );\n\t\t}\n\n\t\treturn valueMapping;\n\t}\n\n\tprotected MappingModelExpressible<?> getInferredValueMapping() {\n\t\tfinal var inferredMapping = resolveInferredType();\n\t\tif ( inferredMapping != null ) {\n\t\t\tif ( inferredMapping instanceof PluralAttributeMapping pluralAttributeMapping ) {\n\t\t\t\treturn pluralAttributeMapping.getElementDescriptor();\n\t\t\t}\n\t\t\tif ( inferredMapping instanceof TupleMappingModelExpressible tuple ) {\n\t\t\t\tfinal var elementExpressible =\n\t\t\t\t\t\ttuple.findComponentMappingModelExpressible( CollectionPart.Nature.ELEMENT.getName() );\n\t\t\t\treturn elementExpressible == null ? inferredMapping : elementExpressible;\n\t\t\t}\n\t\t\telse if ( !( inferredMapping instanceof JavaObjectType ) ) {\n\t\t\t\t// Never report back the \"object type\" as inferred type and instead rely on the value type","sourceCodeStart":6506,"sourceCodeEnd":6542,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java#L6506-L6542","documentation":"determineValueMapping could not resolve a MappingModelExpressible for an SqmExpression: it found no value mapping for the expression itself and no inferred type on the inferrable-type stack. Literals are explicitly tolerated (null is returned), but every other unmappable expression aborts translation with a ConversionException echoing the expression.","triggerScenarios":"An untyped 'null' in the select list or order-by with nothing to infer the type from; criteria expressions typed Object; arithmetic over expressions whose operand types cannot be resolved (e.g. parameters of unknown type on both sides); comparing a subquery result that itself has no mapping.","commonSituations":"Dynamic criteria queries building projections from loosely typed expressions; HQL with coalesce/cast of null without a typed second branch; mixing parameters of raw types in predicates; queries that worked on older 6.x and break after inference changes.","solutions":["Give the expression a type to infer from: 'cast(null as Integer)', 'coalesce(x, 0)' with typed branches","Use typed parameters (cb.parameter(Integer.class)) instead of raw Object ones","Reference a mapped path on one side of the expression so the other side can be inferred","Simplify the expression tree - split compound arithmetic into steps Hibernate can type"],"exampleFix":"// before\nselect o.id, null from Ord o order by 2\n\n// after\nselect o.id, cast(null as Integer) from Ord o","handlingStrategy":"try-catch","validationCode":"// For dynamic criteria projections: reject expressions without a resolvable Java type\nExpression<?> sel = ...;\nif (sel.getJavaType() == Object.class || sel.getJavaType() == null) {\n    throw new IllegalArgumentException(\"Projection lacks a concrete type; wrap with cb.cast(...));\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return session.createQuery(cq).getResultList();\n} catch (org.hibernate.query.sqm.tree.SqmConversionException | RuntimeException e) {\n    // ConversionException extends HibernateException; detect by class name to stay import-safe\n    if (e.getClass().getSimpleName().equals(\"ConversionException\")) {\n        log.error(\"Unresolvable expression type in criteria query\", e);\n    }\n    throw e;\n}","preventionTips":["Never leave a bare null in projections - always cast(null as T)","Type every parameter and avoid Object-typed expressions in criteria trees","Keep at least one mapped path on one side of parameterized predicates"],"tags":["hibernate","hql","criteria","type-inference","query-translation"],"backgroundTag":"unresolved-value-mapping","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}