{"record":{"id":"1c6fcd9fad52b417","repo":"hibernate/hibernate-orm","slug":"cannot-augment-a-subquery","errorCode":null,"errorMessage":"Cannot augment a subquery","messagePattern":"Cannot augment a subquery","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java","lineNumber":166,"sourceCode":"\t\treturn specifications;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic SelectionSpecification<T> restrict(@Nonnull Restriction<? super T> restriction) {\n\t\tspecifications.add( (sqmStatement, root) -> {\n\t\t\tfinal var sqmPredicate = SqmUtil.restriction( sqmStatement, resultType, restriction );\n\t\t\tsqmStatement.getQuerySpec().applyPredicate( sqmPredicate );\n\t\t} );\n\t\treturn this;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic SelectionSpecification<T> augment(@Nonnull Augmentation<T> augmentation) {\n\t\tspecifications.add( (sqmStatement, root) -> {\n\t\t\tif ( !( sqmStatement instanceof SqmSelectStatement<T> selectStatement ) ) {\n\t\t\t\tthrow new IllegalStateException( \"Cannot augment a subquery\" );\n\t\t\t}\n\t\t\taugmentation.augment( sqmStatement.nodeBuilder(), selectStatement, root );\n\t\t} );\n\t\treturn this;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic SelectionSpecification<T> fetch(@Nonnull Path<T, ?> fetchPath) {\n\t\tspecifications.add( (sqmStatement, root) -> fetchPath.fetch( root ) );\n\t\treturn this;\n\t}\n\n\t@Nonnull\n\t@Override\n\tpublic SelectionSpecification<T> sort(@Nonnull Order<? super T> order) {\n\t\tspecifications.add( (sqmStatement, root) -> addOrder( order, sqmStatement ) );\n\t\treturn this;","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/specification/internal/SelectionSpecificationImpl.java#L148-L184","documentation":"Error \"Cannot augment a subquery\" thrown in hibernate/hibernate-orm.","triggerScenarios":"A runtime precondition of the Hibernate query API is violated: Cannot augment a subquery","commonSituations":"Application code or configuration calls the query API in a way that violates its documented contract; the interpolated values in the message identify the offending input.","solutions":["A subquery cannot be augmented by a specification. Apply the specification to the outer query."],"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"}