hibernate/hibernate-orm · error · IllegalSelectQueryException
Not a select query
Error message
Not a select query
What it means
IllegalSelectQueryException from errorIfNotSelectForSure: the native SQL is unequivocally known not to be a select (e.g. it starts with update/delete/insert), yet a selection-only operation was attempted.
Solutions
- The method was called on a mutation native query but requires a SELECT query.
- Use a SELECT native query, or use executeUpdate() for mutation queries.
Defensive patterns
Strategy: validation
When it happens
Trigger: A query object is used through an interface or role it does not implement.
Common situations: Casting or unwrapping a native/HQL, select/mutation query to the wrong type, or passing a non-property path where one is required.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ec1872bbf59a7fa9.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:725
@Nonnull
public QueryParameterBindings getParameterBindings() {
return getQueryParameterBindings();
}
@Override
public Class<R> getResultType() {
errorIfNotSelectForSure();
return resultType;
}
private boolean isNotSelectForSure() {
return isSelectQuery() == Boolean.FALSE;
}
private void errorIfNotSelectForSure() {
if ( isNotSelectForSure() ) {
// we unequivocally know it IS NOT a select query
throw new IllegalSelectQueryException( "Not a select query", sqlString );
}
}
private void errorIfSelectForSure() {
if ( isSelectQuery() == Boolean.TRUE ) {
// we unequivocally know it IS a select query
throw new IllegalSelectQueryException( "Not a mutation query", sqlString );
}
}
@Override
@Nullable
public Class<R> getTargetType() {
return resultType;
}
@Override
@NonnullView on GitHub (pinned to fad1729dce)