hibernate/hibernate-orm · error · ConversionException

Could not determine ValueMapping for SqmParameter: {}

Error message

Could not determine ValueMapping for SqmParameter: {}

What it means

The parameter-side counterpart of the expression error: resolveInferredValueMappingForParameter matched none of the known shapes (model part, basic mapping, entity persister via singular attribute, ...) and context inference returned nothing usable, so translation fails with a ConversionException naming the SqmParameter.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/sql/spi/BaseSqmToSqlAstConverter.java:6671

				if ( basicTypeForJavaType != null ) {
					return basicTypeForJavaType;
				}
				else {
					if ( paramSqmType instanceof EntityDomainType<?> entityDomainType ) {
						return resolveEntityPersister( entityDomainType );
					}
					else if ( paramSqmType instanceof SingularAttribute<?, ?> singularAttribute ) {
						if ( singularAttribute.getType() instanceof EntityDomainType<?> entityDomainType ) {
							return resolveEntityPersister( entityDomainType );
						}
					}
					// inferredMapping is null or JavaObjectType and we cannot deduct the type
					return inferredMapping;
				}
			}
		}
		else {
			throw new ConversionException( "Could not determine ValueMapping for SqmParameter: " + sqmParameter );
		}
	}

	private static boolean canUseInferredType(MappingModelExpressible<?> bindType, MappingModelExpressible<?> inferredType) {
		if ( inferredType.getJdbcTypeCount() != 1 ) {
			// The inferred type is an embeddable or entity with embeddable id, which is more concrete
			return true;
		}
		final var bindJdbcType = bindType.getSingleJdbcMapping().getJdbcType();
		final var inferredJdbcType = inferredType.getSingleJdbcMapping().getJdbcType();
		// If the bind type has a different JDBC type, we prefer that over the inferred type.
		return bindJdbcType == inferredJdbcType
			|| bindJdbcType instanceof ArrayJdbcType bindArrayType
				&& inferredJdbcType instanceof ArrayJdbcType inferredArrayType
				&& bindArrayType.getElementJdbcType() == inferredArrayType.getElementJdbcType();
	}

	private MappingModelExpressible<?> resolveInferredValueMappingForParameter(MappingModelExpressible<?> inferredValueMapping) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Create criteria parameters with a concrete type: cb.parameter(String.class) instead of Object.class
  2. Ensure at least one side of each predicate is a mapped path so the parameter can be inferred
  3. Bind with an explicit type hint where the API allows it (setParameter(name, value, type))
  4. Upgrade to the latest 6.x/7.x patch - parameter inference improves release to release

Example fix

// before
ParameterExpression<Object> p = cb.parameter(Object.class);
cb.equal(root.get("name"), p);

// after
ParameterExpression<String> p = cb.parameter(String.class);
cb.equal(root.get("name"), p);
Defensive patterns

Strategy: validation

Validate before calling

// Validate criteria parameters carry concrete types before compiling
for (jakarta.persistence.Parameter<?> p : query.getParameters()) {
    if (p.getParameterType() == null || p.getParameterType() == Object.class) {
        throw new IllegalStateException("Untyped parameter " + p + " - create with cb.parameter(ConcreteType.class)");
    }
}

Try / catch

try {
    return session.createQuery(cq).getResultList();
} catch (RuntimeException e) {
    if (e.getClass().getSimpleName().equals("ConversionException")
            && e.getMessage() != null && e.getMessage().contains("SqmParameter")) {
        log.error("Parameter without resolvable mapping - type your cb.parameter(...) calls");
    }
    throw e;
}

Prevention

When it happens

Trigger: JPA criteria parameters created as raw ParameterExpression without a usable type (Object.class); parameters in select lists or predicates with no mapped expression on the other side; null-valued bound parameters whose type cannot be inferred; HQL literal-less predicates where both sides are parameters.

Common situations: Dynamic query builders that genericize parameter types; queries generated from user filters where a branch compares parameter to parameter; Hibernate version upgrades where previous lenient inference was removed; criteria fragments shared across queries.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/03715a4d26a09aea. Report an issue: GitHub.