hibernate/hibernate-orm · error · IllegalStateException
Cannot convert a native query to a typed query
Error message
Cannot convert a native query to a typed query
What it means
Error "Cannot convert a native query to a typed query" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java:858
@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() );
}
@Override
@Nonnull
public <T> SelectionQueryImplementor<T> withResultSetMapping(
@Nonnull jakarta.persistence.sql.ResultSetMapping<T> mapping) {
errorIfNotSelectForSure();
final var query = new NativeQueryImpl<>( this, mapping );
query.applyEntityMappingLockMode( mapping );
return query;
}View on GitHub (pinned to fad1729dce)
Solutions
- A native query cannot be converted to a JPA TypedQuery.
- Use createNativeQuery(sql, ResultClass) or rewrite in HQL with createQuery(hql, ResultClass).
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/302f6657e57c7ec5.
Report an issue: GitHub.