hibernate/hibernate-orm · error · IllegalArgumentException

Not an entity type or supertype of an entity type: {}

Error message

Not an entity type or supertype of an entity type: {}

What it means

Error "Not an entity type or supertype of an entity type: {}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java:470

		return eventListenerGroups;
	}

	@Override
	@Nonnull
	public <E> EntityListenerRegistration addListener(
			@Nonnull Class<E> entityClass,
			@Nonnull Class<? extends Annotation> callbackType,
			@Nonnull Consumer<? super E> callback) {
		final var type = CallbackType.fromCallbackAnnotation( callbackType );
		final List<EntityListenerRegistration> registrations = new ArrayList<>();
		getMappingMetamodel().forEachEntityDescriptor( persister -> {
			final var mappedClass = persister.getMappedClass();
			if ( mappedClass != null && entityClass.isAssignableFrom( mappedClass ) ) {
				registrations.add( addListener( entityClass, persister, type, callback ) );
			}
		} );
		if ( registrations.isEmpty() ) {
			throw new IllegalArgumentException( "Not an entity type or supertype of an entity type: " + entityClass.getName() );
		}
		return registrations.size() == 1
				? registrations.get( 0 )
				: () -> registrations.forEach( EntityListenerRegistration::cancel );
	}

	private static <E> EntityListenerRegistration addListener(
			Class<E> entityClass,
			EntityPersister persister,
			CallbackType callbackType,
			Consumer<? super E> callback) {
		return persister.getEntityCallbacks().addListener(
				callbackType,
				entity -> callback.accept( entityClass.cast( entity ) )
		);
	}

	@Override

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass an entity type (or supertype of entities) to the operation; check the class/name for correctness.

When it happens

Trigger: Thrown when a metamodel lookup is done for a class that is not an entity or entity supertype.

Common situations: Typical situations: passing an embeddable or unmapped class to an entity lookup; wrong generic type argument.


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