{"record":{"id":"e27962c708454d97","repo":"hibernate/hibernate-orm","slug":"cycle-attribute-s-not-found-in-the-cte-s","errorCode":null,"errorMessage":"Cycle attribute '%s' not found in the CTE %s","messagePattern":"Cycle attribute '(.+?)' not found in the CTE (.+?)","errorType":"exception","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java","lineNumber":907,"sourceCode":"\t\t\t\t\tapplySearchClause( cteDefinition, searchClauseContext );\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\tprivate void applyCycleClause(JpaCteCriteria<?> cteDefinition, HqlParser.CycleClauseContext ctx) {\n\t\tfinal var attributesContext = ctx.cteAttributes();\n\t\tfinal String cycleMarkAttributeName = visitIdentifier( ctx.identifier(0) );\n\t\tfinal List<JpaCteCriteriaAttribute> cycleAttributes =\n\t\t\t\tnew ArrayList<>( ( attributesContext.getChildCount() + 1 ) >> 1 );\n\t\tfinal var identifiers = attributesContext.identifier();\n\t\tfinal var type = cteDefinition.getType();\n\t\tfor ( int i = 0; i < identifiers.size(); i ++ ) {\n\t\t\tfinal String attributeName = visitIdentifier( identifiers.get( i ) );\n\t\t\tfinal JpaCteCriteriaAttribute attribute = type.getAttribute( attributeName );\n\t\t\tif ( attribute == null ) {\n\t\t\t\tthrow new SemanticException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\t\"Cycle attribute '%s' not found in the CTE %s\",\n\t\t\t\t\t\t\t\tattributeName,\n\t\t\t\t\t\t\t\tcteDefinition.getName()\n\t\t\t\t\t\t),\n\t\t\t\t\t\tquery\n\t\t\t\t);\n\t\t\t}\n\t\t\tcycleAttributes.add( attribute );\n\t\t}\n\n\t\tfinal String cyclePathAttributeName;\n\t\tfinal Object cycleValue;\n\t\tfinal Object noCycleValue;\n\t\tif ( ctx.TO() != null && ctx.DEFAULT() != null ) {\n\t\t\tfinal var cycleLiteral = (SqmLiteral<?>) visitLiteral( ctx.literal(0) );\n\t\t\tfinal var noCycleLiteral = (SqmLiteral<?>) visitLiteral( ctx.literal(1) );\n\t\t\tcycleValue = cycleLiteral.getLiteralValue();","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java#L889-L925","documentation":"Raised (as SemanticException, formatted via String.format) while applying a recursive CTE 'cycle' clause: one of the attribute names listed in the cycle clause does not exist as an attribute of the CTE type. The offending inputs are the missing cycle attribute name and the CTE name, both reported in the message with the originating query.","triggerScenarios":"A runtime precondition of the Hibernate API is violated.","commonSituations":"Occurs when application code or configuration does not satisfy the documented contract of the API being called.","solutions":["Define the cycle attribute in the CTE's search/cycle clause matching an exposed CTE column.","Check the attribute name against the CTE definition."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}