{"record":{"id":"1be387cbf34221dc","repo":"hibernate/hibernate-orm","slug":"the-jpa-specification-does-not-support-subqueries-1be387","errorCode":null,"errorMessage":"The JPA specification does not support subqueries in the from clause. Please disable the JPA query compliance if you want to use this feature.","messagePattern":"The JPA specification does not support subqueries in the from clause\\. 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/AbstractSqmSelectQuery.java","lineNumber":364,"sourceCode":"\t\treturn root;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic <X> SqmRoot<X> from(@Nonnull EntityType<X> entityType) {\n\t\treturn addRoot(\n\t\t\t\tnew SqmRoot<>(\n\t\t\t\t\t\t(EntityDomainType<X>) entityType,\n\t\t\t\t\t\tgenerateAlias(),\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\tnodeBuilder()\n\t\t\t\t)\n\t\t);\n\t}\n\n\tprivate void validateComplianceFromSubQuery() {\n\t\tif ( nodeBuilder().isJpaQueryComplianceEnabled() ) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"The JPA specification does not support subqueries in the from clause. \"\n\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// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\t// Selection\n\n\t@Override\n\tpublic boolean isDistinct() {\n\t\treturn getQuerySpec().isDistinct();\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic SqmSelectQuery<T> distinct(boolean distinct) {\n\t\tgetQuerySpec().setDistinct( distinct );\n\t\treturn this;","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/AbstractSqmSelectQuery.java#L346-L382","documentation":"Error \"The JPA specification does not support subqueries in the from clause. Please disable the JPA query compliance if you want to use this feature.\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A subquery is used in the FROM clause while JPA query compliance mode is enabled; plain JPA does not allow derived tables in FROM.","commonSituations":"Porting HQL with a FROM-clause subquery to the Criteria API; fix by disabling JPA compliance or rewriting the query.","solutions":["Disable JPA query compliance to allow subqueries in the FROM clause (e.g. set jpaCompliance / use Hibernate-specific criteria APIs).","Rewrite the query to avoid a subquery in FROM: move the subquery into the WHERE clause as a correlated subquery or use a join.","Use a native SQL query or a HQL query string, which do not go through the JPA-compliance check."],"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"}