quarkusio/quarkus · error · IllegalArgumentException

Unexpected Query class: '${className}', where 'org.hibernate

Error message

Unexpected Query class: '${className}', where 'org.hibernate.query.sqm.SqmQuery' or 'org.hibernate.query.Query' is expected.

What it means

When projecting a Panache query, getQueryString() extracts the JPQL string from the underlying Hibernate query. It expects an SqmQuery (normal case) or a legacy org.hibernate.query.Query. Any other implementation is unexpected and throws IllegalArgumentException with the offending class name.

Source

Thrown at extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java:514

        return new NonThrowingCloseable() {
            @Override
            public void close() {
                for (Entry<String, Map<String, Object>> entry : filters.entrySet()) {
                    session.disableFilter(entry.getKey());
                }
            }
        };
    }

    @SuppressWarnings("rawtypes")
    public static String getQueryString(SelectionQuery hibernateQuery) {
        if (hibernateQuery instanceof SqmQuery) {
            return ((SqmQuery) hibernateQuery).getQueryString();
        } else if (hibernateQuery instanceof org.hibernate.query.Query) {
            // In theory we never use a Query, but who knows.
            return ((org.hibernate.query.Query) hibernateQuery).getQueryString();
        } else {
            throw new IllegalArgumentException("Unexpected Query class: '" + hibernateQuery.getClass().getName() + "', where '"
                    + SqmQuery.class.getName() + "' or '"
                    + org.hibernate.query.Query.class + "' is expected.");
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Verify your Hibernate ORM and Quarkus versions are a compatible, supported pair (align quarkus platform BOM).
  2. Remove wrappers/interceptors around the Hibernate session that substitute custom Query implementations.
  3. Check the reported className in the message and confirm which component produced that Query implementation.
  4. Avoid calling project() on queries produced through non-standard paths; write the projection JPQL explicitly with find(query, Class).
Defensive patterns

Strategy: try-catch

Type guard

static boolean isSupportedHibernateQuery(Object q) {
    return q instanceof org.hibernate.query.sqm.SqmQuery
        || q instanceof org.hibernate.query.Query;
}

Try / catch

try {
    dto = query.find("select p from Person p", PersonDto.class).list();
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unexpected Query class")) {
        // inspect e.getMessage() className; align Hibernate/Quarkus versions or unwrap the custom Query
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling project(Class) on a query whose underlying Hibernate query object is neither SqmQuery nor org.hibernate.query.Query (custom Query implementations, wrappers, or incompatible Hibernate versions).

Common situations: Hibernate ORM version upgrades changing query implementation classes; third-party libraries wrapping the Hibernate Session/Query; interceptors returning custom Query implementations.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/1246a6e6d2b85e44. Report an issue: GitHub.