hibernate/hibernate-orm · error · IllegalStateException

The JPA specification does not support subqueries in the fro

Error message

The JPA specification does not support subqueries in the from clause. Please disable the JPA query compliance if you want to use this feature.

What it means

Error "The JPA specification does not support subqueries in the from clause. Please disable the JPA query compliance if you want to use this feature." thrown in hibernate/hibernate-orm.

Source

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

		return root;
	}

	@Nonnull
	@Override
	public <X> SqmRoot<X> from(@Nonnull EntityType<X> entityType) {
		return addRoot(
				new SqmRoot<>(
						(EntityDomainType<X>) entityType,
						generateAlias(),
						true,
						nodeBuilder()
				)
		);
	}

	private void validateComplianceFromSubQuery() {
		if ( nodeBuilder().isJpaQueryComplianceEnabled() ) {
			throw new IllegalStateException(
					"The JPA specification does not support subqueries in the from clause. "
					+ "Please disable the JPA query compliance if you want to use this feature." );
		}
	}

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Selection

	@Override
	public boolean isDistinct() {
		return getQuerySpec().isDistinct();
	}

	@Nonnull
	@Override
	public SqmSelectQuery<T> distinct(boolean distinct) {
		getQuerySpec().setDistinct( distinct );
		return this;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Disable JPA query compliance to allow subqueries in the FROM clause (e.g. set jpaCompliance / use Hibernate-specific criteria APIs).
  2. Rewrite the query to avoid a subquery in FROM: move the subquery into the WHERE clause as a correlated subquery or use a join.
  3. Use a native SQL query or a HQL query string, which do not go through the JPA-compliance check.

When it happens

Trigger: A subquery is used in the FROM clause while JPA query compliance mode is enabled; plain JPA does not allow derived tables in FROM.

Common situations: Porting HQL with a FROM-clause subquery to the Criteria API; fix by disabling JPA compliance or rewriting the query.


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