hibernate/hibernate-orm · error · SemanticException

Cycle attribute ' ' not found in the CTE

Error message

Cycle attribute '%s' not found in the CTE %s

What it means

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.

Solutions

  1. Define the cycle attribute in the CTE's search/cycle clause matching an exposed CTE column.
  2. Check the attribute name against the CTE definition.
Defensive patterns

Strategy: validation

When it happens

Trigger: A runtime precondition of the Hibernate API is violated.

Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/e27962c708454d97. Report an issue: GitHub.

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:907

					applySearchClause( cteDefinition, searchClauseContext );
				}
				return true;
		}
		return false;
	}

	private void applyCycleClause(JpaCteCriteria<?> cteDefinition, HqlParser.CycleClauseContext ctx) {
		final var attributesContext = ctx.cteAttributes();
		final String cycleMarkAttributeName = visitIdentifier( ctx.identifier(0) );
		final List<JpaCteCriteriaAttribute> cycleAttributes =
				new ArrayList<>( ( attributesContext.getChildCount() + 1 ) >> 1 );
		final var identifiers = attributesContext.identifier();
		final var type = cteDefinition.getType();
		for ( int i = 0; i < identifiers.size(); i ++ ) {
			final String attributeName = visitIdentifier( identifiers.get( i ) );
			final JpaCteCriteriaAttribute attribute = type.getAttribute( attributeName );
			if ( attribute == null ) {
				throw new SemanticException(
						String.format(
								"Cycle attribute '%s' not found in the CTE %s",
								attributeName,
								cteDefinition.getName()
						),
						query
				);
			}
			cycleAttributes.add( attribute );
		}

		final String cyclePathAttributeName;
		final Object cycleValue;
		final Object noCycleValue;
		if ( ctx.TO() != null && ctx.DEFAULT() != null ) {
			final var cycleLiteral = (SqmLiteral<?>) visitLiteral( ctx.literal(0) );
			final var noCycleLiteral = (SqmLiteral<?>) visitLiteral( ctx.literal(1) );
			cycleValue = cycleLiteral.getLiteralValue();

View on GitHub (pinned to fad1729dce)