hibernate/hibernate-orm · error · SemanticException

Could not resolve treat target type '" + treatTargetName + "

Error message

Could not resolve treat target type '" + treatTargetName + "'

What it means

Error "Could not resolve treat target type '" + treatTargetName + "'" thrown in hibernate/hibernate-orm.

Source

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

	@Override
	public SqmPath<?> visitTreatedNavigablePath(HqlParser.TreatedNavigablePathContext ctx) {
		final var consumer = dotIdentifierConsumerStack.getCurrent();
		final boolean madeNested;
		if ( consumer instanceof QualifiedJoinPathConsumer qualifiedJoinPathConsumer ) {
			madeNested = !qualifiedJoinPathConsumer.isNested();
			if ( madeNested ) {
				qualifiedJoinPathConsumer.setNested( true );
			}
		}
		else {
			madeNested = false;
		}
		consumeManagedTypeReference( ctx.path() );

		final String treatTargetName = ctx.simplePath().getText();
		final String importableName = getJpaMetamodel().qualifyImportableName( treatTargetName );
		if ( importableName == null ) {
			throw new SemanticException( "Could not resolve treat target type '" + treatTargetName + "'", query );
		}

		final boolean hasContinuation = ctx.getChildCount() == 7;
		consumer.consumeTreat( importableName, !hasContinuation );
		SqmPath<?> result = (SqmPath<?>) consumer.getConsumedPart();

		if ( hasContinuation ) {
			if ( madeNested ) {
				// Reset the nested state before consuming the terminal identifier
				( (QualifiedJoinPathConsumer) consumer ).setNested( false );
			}
			final boolean addConsumer = !( consumer instanceof QualifiedJoinPathConsumer );
			if ( addConsumer ) {
				dotIdentifierConsumerStack.push(
						new BasicDotIdentifierConsumer( result, this ) {
							@Override
							protected void reset() {
							}

View on GitHub (pinned to fad1729dce)

Solutions

  1. The TREAT target type name could not be resolved. Use the entity name (or imported FQN) of a mapped subtype in treat(x as Type).

When it happens

Trigger: A name/path expected to denote an entity type does not: Could not resolve treat target type '" + treatTargetName + "'

Common situations: Passing non-entity arguments to version()/naturalid(), or a TREAT target / entity name that is not a mapped entity; commonly a typo or unmapped class.


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