{"record":{"id":"1246a6e6d2b85e44","repo":"quarkusio/quarkus","slug":"unexpected-query-class-classname-where-org","errorCode":null,"errorMessage":"Unexpected Query class: '${className}', where 'org.hibernate.query.sqm.SqmQuery' or 'org.hibernate.query.Query' is expected.","messagePattern":"Unexpected Query class: '(.+?)', where 'org\\.hibernate\\.query\\.sqm\\.SqmQuery' or 'org\\.hibernate\\.query\\.Query' is expected\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java","lineNumber":514,"sourceCode":"        return new NonThrowingCloseable() {\n            @Override\n            public void close() {\n                for (Entry<String, Map<String, Object>> entry : filters.entrySet()) {\n                    session.disableFilter(entry.getKey());\n                }\n            }\n        };\n    }\n\n    @SuppressWarnings(\"rawtypes\")\n    public static String getQueryString(SelectionQuery hibernateQuery) {\n        if (hibernateQuery instanceof SqmQuery) {\n            return ((SqmQuery) hibernateQuery).getQueryString();\n        } else if (hibernateQuery instanceof org.hibernate.query.Query) {\n            // In theory we never use a Query, but who knows.\n            return ((org.hibernate.query.Query) hibernateQuery).getQueryString();\n        } else {\n            throw new IllegalArgumentException(\"Unexpected Query class: '\" + hibernateQuery.getClass().getName() + \"', where '\"\n                    + SqmQuery.class.getName() + \"' or '\"\n                    + org.hibernate.query.Query.class + \"' is expected.\");\n        }\n    }\n}\n","sourceCodeStart":496,"sourceCodeEnd":520,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/panache/hibernate-orm-panache-common/runtime/src/main/java/io/quarkus/hibernate/orm/panache/common/runtime/CommonPanacheQueryImpl.java#L496-L520","documentation":"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.","triggerScenarios":"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).","commonSituations":"Hibernate ORM version upgrades changing query implementation classes; third-party libraries wrapping the Hibernate Session/Query; interceptors returning custom Query implementations.","solutions":["Verify your Hibernate ORM and Quarkus versions are a compatible, supported pair (align quarkus platform BOM).","Remove wrappers/interceptors around the Hibernate session that substitute custom Query implementations.","Check the reported className in the message and confirm which component produced that Query implementation.","Avoid calling project() on queries produced through non-standard paths; write the projection JPQL explicitly with find(query, Class)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"static boolean isSupportedHibernateQuery(Object q) {\n    return q instanceof org.hibernate.query.sqm.SqmQuery\n        || q instanceof org.hibernate.query.Query;\n}","tryCatchPattern":"try {\n    dto = query.find(\"select p from Person p\", PersonDto.class).list();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unexpected Query class\")) {\n        // inspect e.getMessage() className; align Hibernate/Quarkus versions or unwrap the custom Query\n    }\n    throw e;\n}","preventionTips":["Keep Quarkus and Hibernate ORM versions aligned via the Quarkus BOM.","Avoid session/query wrappers that return custom Query implementations.","Test projection queries after any Hibernate upgrade."],"tags":["panache","hibernate","projection","class-mismatch"],"backgroundTag":"unexpected-query-implementation","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}