hibernate/hibernate-orm · error · IllegalArgumentException

Given class is not an entity: {}

Error message

Given class is not an entity: {}

What it means

Error "Given class is not an entity: {}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java:429

	@Override
	public void addNamedEntityGraph(String graphName, RootGraphImplementor<?> rootGraph) {
		final var old = entityGraphMap.put( graphName, rootGraph.makeCopy( false, graphName ) );
		if ( old != null ) {
			CORE_LOGGER.tracef( "EntityGraph named '%s' was replaced", graphName );
		}
	}

	@Override
	public RootGraphImplementor<?> findEntityGraphByName(String name) {
		return entityGraphMap.get( name );
	}

	@Override
	public <T> List<EntityGraph<? super T>> findEntityGraphsByJavaType(Class<T> entityClass) {
		final var entityType = entity( entityClass );
		//noinspection ConstantValue
		if ( entityType == null ) {
			throw new IllegalArgumentException( "Given class is not an entity: " + entityClass.getName() );
		}
		final List<EntityGraph<? super T>> results = new ArrayList<>();
		for ( var entityGraph : entityGraphMap.values() ) {
			if ( entityGraph.appliesTo( entityType ) ) {
				@SuppressWarnings("unchecked") // safe, we just checked
				var result = (RootGraphImplementor<? super T>) entityGraph;
				results.add( result );
			}
		}
		return results;
	}

	@Override
	public <T> Map<String, EntityGraph<? extends T>> getNamedEntityGraphs(Class<T> entityClass) {
		final var entityType = entity( entityClass );
		//noinspection ConstantValue
		if ( entityType == null ) {
			throw new IllegalArgumentException( "Given class is not an entity: " + entityClass.getName() );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass a class annotated @Entity that is managed by this persistence unit.

When it happens

Trigger: Thrown when an operation requiring an entity type is given a class that is not a mapped entity.

Common situations: See trigger scenarios.


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