hibernate/hibernate-orm · error · InstantiationException

Cannot instantiate query result type

Error message

Cannot instantiate query result type

What it means

Error "Cannot instantiate query result type" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java:73

					final var parameterTypes = candidate.getParameterTypes();
					if ( parameterTypes.length == elements.length ) {
						// found a candidate with the right number
						// of parameters
						if ( constructor == null ) {
							constructor = resultClass.getDeclaredConstructor( parameterTypes );
							constructor.setAccessible( true );
						}
						else {
							// ambiguous, more than one constructor
							// with the right number of parameters
							constructor = null;
							break;
						}
					}
				}
			}
			catch (Exception e) {
				throw new InstantiationException( "Cannot instantiate query result type", resultClass, e );
			}
			if ( constructor == null ) {
				final var message = new StringBuilder();
				message.append( "Result class" )
						.append( " must have exactly one constructor with " )
						.append( elements.length )
						.append( " parameters - found ['" );
				boolean first = true;
				for ( var c : resultClass.getDeclaredConstructors() ) {
					if ( c.getParameterCount() == elements.length ) {
						if ( !first ) {
							message.append( "', '" );
						}
						message.append( constructorSignature( c ) );
						first = false;
					}
				}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Ensure the result class has a public constructor matching the selected columns; use Tuple or Object[] result instead.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java:73 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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