hibernate/hibernate-orm · error · IllegalArgumentException

Not an entity

Error message

Not an entity: ${entityName}

What it means

Thrown by the JPA metamodel entity(String) accessor when findEntityType returns null, i.e. no managed type registered under the given entity name is an EntityDomainType. The JPA specification requires IllegalArgumentException here for unknown entity names, so this is the spec-mandated guard on the entity-name argument; the faulty input is entityName, which is not a known entity in the session factory's metamodel (misspelled name, unimported class name, or an embeddable/mapped-superclass name).

Solutions

  1. Pass the name of a mapped entity; check spelling and that the class is annotated @Entity.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown when JpaMetamodel.entity() is called with a type name 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/4fdee0e22570aa61. Report an issue: GitHub.

Appendix: source

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

		for ( var entry : managedTypeByName.entrySet() ) {
			if ( entry.getValue() instanceof EntityDomainType<?> possibility ) {
				if ( entityName.equals( possibility.getName() ) ) {
					return possibility;
				}
			}
		}

		return null;
	}

	@Override
	@Nonnull
	public EntityDomainType<?> entity(@Nullable String entityName) {
		final EntityDomainType<?> entityType = findEntityType( entityName );
		if ( entityType == null ) {
			// per JPA, this is an exception
			throw new IllegalArgumentException( "Not an entity: " + entityName );
		}
		return entityType;

	}

	@Override
	@Nullable
	public EmbeddableDomainType<?> findEmbeddableType(@Nullable String embeddableName) {
		if ( embeddableName == null ) {
			return null;
		}
		final var managedType = managedTypeByName.get( embeddableName );
		if ( !( managedType instanceof EmbeddableDomainType<?> embeddableDomainType ) ) {
			return null;
		}
		return embeddableDomainType;
	}

View on GitHub (pinned to fad1729dce)