{"record":{"id":"b9601c54a0005a9e","repo":"hibernate/hibernate-orm","slug":"cannot-instantiate-query-result-type-argument-typ","errorCode":null,"errorMessage":"Cannot instantiate query result type, argument types are unknown ","messagePattern":"Cannot instantiate query result type, argument types are unknown ","errorType":"exception","errorClass":"InstantiationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/sql/results/internal/RowTransformerConstructorImpl.java","lineNumber":41,"sourceCode":" * @author Gavin King\n */\npublic class RowTransformerConstructorImpl<T> implements RowTransformer<T> {\n\tprivate final Class<T> type;\n\tprivate final Constructor<T> constructor;\n\n\tpublic RowTransformerConstructorImpl(\n\t\t\tClass<T> type,\n\t\t\tTupleMetadata tupleMetadata,\n\t\t\tTypeConfiguration typeConfiguration) {\n\t\tthis.type = type;\n\t\tassert tupleMetadata != null : \"TupleMetadata must not be null\";\n\t\tfinal List<TupleElement<?>> elements = tupleMetadata.getList();\n\t\tfinal List<Class<?>> argumentTypes = elements.stream()\n\t\t\t\t.map( RowTransformerConstructorImpl::resolveElementJavaType )\n\t\t\t\t.collect( toList() );\n\t\tif ( argumentTypes.size() == 1 && argumentTypes.get( 0 ) == null ) {\n\t\t\t// Can not (properly) resolve constructor for single null element\n\t\t\tthrow new InstantiationException( \"Cannot instantiate query result type, argument types are unknown \", type );\n\t\t}\n\n\t\tconstructor = findMatchingConstructor( type, argumentTypes, typeConfiguration );\n\t\tif ( constructor == null ) {\n\t\t\tthrow new InstantiationException( \"Cannot instantiate query result type, found no matching constructor\", type );\n\t\t}\n\t\tconstructor.setAccessible( true );\n\t}\n\n\tprivate static Class<?> resolveElementJavaType(TupleElement<?> element) {\n\t\tif ( element instanceof SqmExpressibleAccessor<?> accessor ) {\n\t\t\tfinal SqmExpressible<?> expressible = accessor.getExpressible();\n\t\t\tif ( expressible != null && expressible.getExpressibleJavaType() != null ) {\n\t\t\t\treturn expressible.getExpressibleJavaType().getJavaTypeClass();\n\t\t\t}\n\t\t}\n\n\t\treturn element.getJavaType();","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/sql/results/internal/RowTransformerConstructorImpl.java#L23-L59","documentation":"Thrown while building RowTransformerConstructorImpl: the query has exactly one selected element and Hibernate could not resolve a Java type for it (resolveElementJavaType returned null because the SqmExpressible has no expressible Java type and TupleElement.getJavaType() is null), so a matching constructor cannot even be searched for. In the standard SQM path this InstantiationException is caught at ConcreteSqmSelectQueryPlan:371 and replaced with the checking transformer, so it usually re-surfaces later as the QueryTypeMismatchException of error 3186 rather than in this raw form.","triggerScenarios":"`select null from Employee e` combined with `SomeClass.class`; a single selection of an expression whose type cannot be determined (untyped native SQL fragment, untyped parameter); requesting a bean result type for a single untyped column.","commonSituations":"Prototyping with `select null` placeholders; queries over database functions or fragments Hibernate cannot type-resolve; migrations where a selection used to be typed and now resolves to null type.","solutions":["Select a typed expression: `select cast(null as string) from Employee e`, or select a real column/function with a known type","If the value genuinely has no type, query with `Object.class` (which skips constructor transformation) instead of a bean class","Give the expression an explicit type via `cast(... as <type>)` in HQL so constructor lookup can proceed"],"exampleFix":"// before\nList<Foo> r = session.createQuery(\"select null from Employee e\", Foo.class).getResultList();\n// after\nList<String> r = session.createQuery(\"select cast(null as string) from Employee e\", String.class).getResultList();","handlingStrategy":"validation","validationCode":"// Avoid untyped single selections; make the type explicit before requesting a bean result type\nString hql = \"select cast(null as string) from Employee e\"; // typed placeholder instead of bare `select null`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never ship `select null` placeholders - use cast(null as <type>) or a real column","When a projection's type is uncertain, query with Object.class first and inspect getClass()","Treat unresolvable expression types in a projection as a query bug, not a runtime concern"],"tags":["hql","tuple","result-type","type-resolution","constructor-transformer"],"backgroundTag":"query-result-type-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}