hibernate/hibernate-orm · error · IllegalArgumentException

Could not resolve named query '{}' for loading entity '{}'

Error message

Could not resolve named query '{}' for loading entity '{}'

What it means

Error "Could not resolve named query '{}' for loading entity '{}'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java:843

		while ( containingClass.getSuperclass() != null ) {
			final var superclass = containingClass.getSuperclass();
			if ( Objects.equals( persistentClass.getWhere(), superclass.getWhere() ) ) {
				containingClass = superclass;
			}
			else {
				break;
			}
		}
		return containingClass;
	}

	@Nonnull
	private NamedQueryMemento<?> getNamedQueryMemento(@Nonnull MetadataImplementor bootModel) {
		final var memento =
				factory.getQueryEngine().getNamedObjectRepository()
						.resolve( factory, bootModel, queryLoaderName );
		if ( memento == null ) {
			throw new IllegalArgumentException( "Could not resolve named query '" + queryLoaderName
					+ "' for loading entity '" + getEntityName() + "'" );
		}
		return memento;
	}

	/**
	 * For Hibernate Reactive
	 */
	protected SingleIdEntityLoader<?> buildSingleIdEntityLoader() {
		if ( hasNamedQueryLoader() ) {
			// We must resolve the named query on-demand through the boot model because it isn't initialized yet
			final var memento = getNamedQueryMemento( null );
			return new SingleIdEntityLoaderProvidedQueryImpl<>( this, memento );
		}
		else {
			return buildSingleIdEntityLoader( new LoadQueryInfluencers( factory ), null );
		}
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Define the named query (@NamedQuery or orm.xml) referenced by the entity loader, or correct the query name in the @Loader mapping.

When it happens

Trigger: Thrown when an entity is configured to load via a named query that cannot be found in the named query registry.

Common situations: See trigger scenarios.


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