hibernate/hibernate-orm · error · IllegalArgumentException

No root entity with alias %s

Error message

No root entity with alias %s

What it means

Error "No root entity with alias %s" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/query/sqm/tree/spi/select/AbstractSqmSelectQuery.java:290

		final var rootList = getQuerySpec().getRootList();
		if ( rootList.size() <= position ) {
			throw new IllegalArgumentException( "Not enough root entities" );
		}
		return castRoot( rootList.get( position ), type );
	}

	/**
	 * @see org.hibernate.query.criteria.JpaCriteriaQuery#getRoot(String, Class)
	 */
	@Nonnull
	public <E> JpaRoot<? extends E> getRoot(String alias, Class<E> type) {
		for ( var root : getQuerySpec().getRootList() ) {
			final String rootAlias = root.getAlias();
			if ( rootAlias != null && rootAlias.equals( alias ) ) {
				return castRoot( root, type );
			}
		}
		throw new IllegalArgumentException( "No root entity with alias " + alias );
	}

	private static <E> JpaRoot<? extends E> castRoot(JpaRoot<?> root, Class<E> type) {
		final var rootEntityType = root.getJavaType();
		if ( rootEntityType == null ) {
			throw new AssertionFailure( "Java type of root entity was null" );
		}
		if ( !type.isAssignableFrom( rootEntityType ) ) {
			throw new IllegalArgumentException( "Root entity of type '" + rootEntityType.getTypeName()
												+ "' did not have the given type '" + type.getTypeName() + "'");
		}
		@SuppressWarnings("unchecked") // safe, we just checked
		final var result = (JpaRoot<? extends E>) root;
		return result;
	}

	@Nonnull
	@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Check the alias passed to the lookup: it must exactly match the alias given to a root in the FROM clause (aliases are case-sensitive).
  2. List the root entities of the query first (e.g. via getRootList()/getRoots()) and use one of their aliases.
  3. If the root was created without an explicit alias, set one when creating the root (criteria.from(Entity.class).alias("e")) and use that alias here.

When it happens

Trigger: A Criteria API query calls a method that looks up a root entity by alias (e.g. AbstractSqmSelectQuery#getRoot(alias)) and no root was registered with that alias.

Common situations: Typo in the alias string, or the alias was never assigned via Root.alias() before lookup.


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