hibernate/hibernate-orm · error · SemanticException

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

Error message

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

What it means

Error "Cycle attribute '%s' not found in the CTE %s" thrown in hibernate/hibernate-orm.

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)

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.

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.