{"record":{"id":"503b0e922596f3c9","repo":"hibernate/hibernate-orm","slug":"no-jdbc-mapping-could-be-inferred-for-parameter","errorCode":null,"errorMessage":"No JDBC mapping could be inferred for parameter - %s","messagePattern":"No JDBC mapping could be inferred for parameter - (.+?)","errorType":"exception","errorClass":"ExecutionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java","lineNumber":106,"sourceCode":"\n\t\tfinal var jdbcMapping = jdbcMapping( executionContext, binding );\n\t\tbindParameterValue( jdbcMapping, statement, binding.getBindValue(), startPosition, executionContext );\n\t}\n\n\tprivate JdbcMapping jdbcMapping(ExecutionContext executionContext, JdbcParameterBinding binding) {\n\t\tJdbcMapping jdbcMapping = binding.getBindType();\n\n\t\tif ( jdbcMapping == null ) {\n\t\t\tjdbcMapping = this.jdbcMapping;\n\t\t}\n\n\t\t// If the parameter type is not known from the context i.e. null or Object, infer it from the bind value\n\t\tif ( jdbcMapping == null || jdbcMapping.getMappedJavaType().getJavaTypeClass() == Object.class ) {\n\t\t\tjdbcMapping = guessBindType( executionContext, binding.getBindValue(), jdbcMapping );\n\t\t}\n\n\t\tif ( jdbcMapping == null ) {\n\t\t\tthrow new ExecutionException( \"No JDBC mapping could be inferred for parameter - \" + this );\n\t\t}\n\n\t\treturn jdbcMapping;\n\t}\n\n\tprotected void bindParameterValue(\n\t\t\tJdbcMapping jdbcMapping,\n\t\t\tPreparedStatement statement,\n\t\t\tObject bindValue,\n\t\t\tint startPosition,\n\t\t\tExecutionContext executionContext)\n\t\t\t\t\tthrows SQLException {\n\t\t//noinspection unchecked\n\t\tjdbcMapping.getJdbcValueBinder()\n\t\t\t\t.bind( statement, bindValue, startPosition, executionContext.getSession() );\n\t}\n\n\tprivate JdbcMapping guessBindType(ExecutionContext executionContext, Object bindValue, JdbcMapping jdbcMapping) {","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/exec/internal/AbstractJdbcParameter.java#L88-L124","documentation":"AbstractJdbcParameter.jdbcMapping() resolves the JdbcMapping for a bind: first the binding's explicit type, then the parameter's own mapping, then guessBindType() from the actual bind value. If all sources yield null - typically an untyped null bound against a parameter with no context type - it throws ExecutionException('No JDBC mapping could be inferred for parameter'). It also re-infers when the current mapping's Java type is plain Object.","triggerScenarios":"setParameter(\"p\", null) or setParameter(1, null) on native or dynamically built queries where no type metadata exists; null binds in custom mutation executors; binding values whose class is not a registered basic type and for which guessBindType finds nothing.","commonSituations":"Native queries 'where col = ?' with a null argument; optional filters in dynamic-query builders bound as null; custom BasicTypes never registered; passing exotic objects (records, JSON wrappers) without a mapper.","solutions":["Bind typed nulls: setParameter(\"p\", null, StringType.INSTANCE) or setParameter(\"p\", new TypedParameterValue<>(StandardBasicTypes.STRING, null))","For native queries prefer overloads that carry types: createNativeQuery(sql, ...).setParameter(1, null, Types.VARCHAR)","Register a BasicType/AttributeConverter for the value's Java type so guessBindType can resolve it","Skip the parameter entirely when the value is null - build the SQL fragment conditionally"],"exampleFix":"// before\nquery.setParameter( \"status\", status ); // status is null, no type context -> throws\n\n// after\nquery.setParameter( \"status\", new TypedParameterValue<>( StandardBasicTypes.STRING, status ) );","handlingStrategy":"validation","validationCode":"// never bind an untyped null\nif ( value == null ) {\n    query.setParameter( name, new TypedParameterValue<>( StandardBasicTypes.STRING, null ) );\n} else {\n    query.setParameter( name, value );\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Wrap null arguments in TypedParameterValue or pass an explicit BasicTypeReference","Prefer typed createNativeQuery/setParameter overloads for native SQL parameters","Register basic types/converters for custom Java types used as query parameters"],"tags":["hibernate","orm","jdbc","parameter-binding","null-handling"],"backgroundTag":"untyped-null-parameter","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}