hibernate/hibernate-orm · error · InstantiationException
Could not instantiate query result type - expected
Error message
Could not instantiate query result type - expected '{}' but found '{}({})' in What it means
Thrown when instantiating the native-query DTO via its constructor: invocation failed because the actual tuple element types/nulls do not match the selected constructor's parameter types; expected vs actual signature shown in the message.
Solutions
- Align the query's selected column types/count with the constructor signature of the result class.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java:122 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/1ee1769ed73ae713.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java:122
return ctor.newInstance( tuple );
}
catch (Exception e) {
final var message = new StringBuilder();
message.append( "Could not instantiate query result type - expected '" )
.append( constructorSignature( ctor ) )
.append( "' but found '" )
.append( ctor.getDeclaringClass().getSimpleName() )
.append( '(' );
for ( int i = 0; i < tuple.length; i++ ) {
final Object value = tuple[i];
if ( i > 0 ) {
message.append( ", " );
}
message.append( value == null ? "null" : value.getClass().getSimpleName() );
}
message.append( ")' in" );
throw new InstantiationException( message.toString(), resultClass, e );
}
}
@Override
public boolean equals(Object obj) {
return obj instanceof NativeQueryConstructorTransformer<?> that
&& this.resultClass == that.resultClass;
// should be safe to ignore the cached constructor here
}
@Override
public int hashCode() {
return resultClass.hashCode();
}
}
View on GitHub (pinned to fad1729dce)