{"record":{"id":"7b141637f309af42","repo":"hibernate/hibernate-orm","slug":"cannot-instantiate-query-result-type","errorCode":null,"errorMessage":"Cannot instantiate query result type","messagePattern":"Cannot instantiate query result type","errorType":"exception","errorClass":"InstantiationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java","lineNumber":73,"sourceCode":"\t\t\t\t\tfinal var parameterTypes = candidate.getParameterTypes();\n\t\t\t\t\tif ( parameterTypes.length == elements.length ) {\n\t\t\t\t\t\t// found a candidate with the right number\n\t\t\t\t\t\t// of parameters\n\t\t\t\t\t\tif ( constructor == null ) {\n\t\t\t\t\t\t\tconstructor = resultClass.getDeclaredConstructor( parameterTypes );\n\t\t\t\t\t\t\tconstructor.setAccessible( true );\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t// ambiguous, more than one constructor\n\t\t\t\t\t\t\t// with the right number of parameters\n\t\t\t\t\t\t\tconstructor = null;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (Exception e) {\n\t\t\t\tthrow new InstantiationException( \"Cannot instantiate query result type\", resultClass, e );\n\t\t\t}\n\t\t\tif ( constructor == null ) {\n\t\t\t\tfinal var message = new StringBuilder();\n\t\t\t\tmessage.append( \"Result class\" )\n\t\t\t\t\t\t.append( \" must have exactly one constructor with \" )\n\t\t\t\t\t\t.append( elements.length )\n\t\t\t\t\t\t.append( \" parameters - found ['\" );\n\t\t\t\tboolean first = true;\n\t\t\t\tfor ( var c : resultClass.getDeclaredConstructors() ) {\n\t\t\t\t\tif ( c.getParameterCount() == elements.length ) {\n\t\t\t\t\t\tif ( !first ) {\n\t\t\t\t\t\t\tmessage.append( \"', '\" );\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmessage.append( constructorSignature( c ) );\n\t\t\t\t\t\tfirst = false;\n\t\t\t\t\t}\n\t\t\t\t}\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java#L55-L91","documentation":"Error \"Cannot instantiate query result type\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java:73 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the result class has a public constructor matching the selected columns; use Tuple or Object[] result instead."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}