hibernate/hibernate-orm · error · IllegalStateException
Cannot convert a native query to a statement
Error message
Cannot convert a native query to a statement
What it means
Error "Cannot convert a native query to a statement" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:847
@Nullable
public Integer getFetchSize() {
return queryOptions.getFetchSize();
}
@Override
@Nullable
public String getCacheRegion() {
return queryOptions.getResultCacheRegionName();
}
@Override
@Nonnull
public MutationQuery asStatement() {
try {
return asMutationQuery();
}
catch (IllegalMutationQueryException e) {
throw new IllegalStateException( "Cannot convert a native query to a statement", e );
}
}
@Override
@Nonnull
public <T> SelectionQuery<T> ofType(@Nonnull Class<T> resultType) {
try {
return asSelectionQuery( resultType );
}
catch (IllegalSelectQueryException e) {
throw new IllegalStateException( "Cannot convert a native query to a typed query", e );
}
}
@Override
@Nonnull
public <T> SelectionQuery<T> withEntityGraph(@Nonnull EntityGraph<T> graph) {
throw new IllegalSelectQueryException( "Not a HQL query", getQueryString() );View on GitHub (pinned to fad1729dce)
Solutions
- A native query cannot be unwrapped/converted to a java.sql.Statement.
- Use session.doWork() or the JDBC connection directly for Statement-level access.
When it happens
Trigger: An API operation is invoked on a query object that does not support it.
Common situations: Calling query hint, locking, pagination, conversion, or mutation APIs on a query kind (native vs HQL, select vs mutation) that does not implement them.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/df851356c18b6de1.
Report an issue: GitHub.