{"record":{"id":"09405b4727826460","repo":"hibernate/hibernate-orm","slug":"the-jpa-specification-does-not-support-subqueries-09405b","errorCode":null,"errorMessage":"The JPA specification does not support subqueries in select clauses. Please disable the JPA query compliance if you want to use this feature.","messagePattern":"The JPA specification does not support subqueries in select clauses\\. Please disable the JPA query compliance if you want to use this feature\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmSelectStatement.java","lineNumber":399,"sourceCode":"\t\t\t\t\t\t\"empty selections passed to criteria query typed as Object\" );\n\t\t\t\tcase 1 -> (JpaSelection<?>) selections.get( 0 );\n\t\t\t\tdefault -> nodeBuilder().array( selections );\n\t\t\t};\n\t\t}\n\t\telse if ( Tuple.class.isAssignableFrom( resultType ) ) {\n\t\t\treturn nodeBuilder().tuple( selections );\n\t\t}\n\t\telse if ( resultType.isArray() ) {\n\t\t\treturn nodeBuilder().array( resultType, selections );\n\t\t}\n\t\telse {\n\t\t\treturn nodeBuilder().construct( resultType, selections );\n\t\t}\n\t}\n\n\tprivate void checkSelectionIsJpaCompliant(Selection<?> selection) {\n\t\tif ( selection instanceof SqmSubQuery<?> ) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"The JPA specification does not support subqueries in select clauses. \" +\n\t\t\t\t\t\t\t\"Please disable the JPA query compliance if you want to use this feature.\" );\n\t\t}\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic SqmSelectStatement<T> orderBy(@Nonnull Order... orders) {\n\t\tfinal SqmOrderByClause sqmOrderByClause = new SqmOrderByClause( orders.length );\n\t\tfor ( Order order : orders ) {\n\t\t\tsqmOrderByClause.addSortSpecification( (SqmSortSpecification) order );\n\t\t}\n\t\tgetQueryPart().setOrderByClause( sqmOrderByClause );\n\t\treturn this;\n\t}\n\n\t@Nonnull\n\t@Override","sourceCodeStart":381,"sourceCodeEnd":417,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/SqmSelectStatement.java#L381-L417","documentation":"Error \"The JPA specification does not support subqueries in select clauses. Please disable the JPA query compliance if you want to use this feature.\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A subquery is placed in the SELECT clause while JPA query compliance mode is enabled.","commonSituations":"Using scalar subqueries in the select list under strict JPA compliance; disable compliance or move the subquery to WHERE.","solutions":["Disable JPA query compliance to allow subqueries in the SELECT clause.","Move the subquery into the WHERE clause or restructure the query to compute the value via a join.","Use HQL or native SQL for this query, which do not enforce the JPA restriction."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}