hibernate/hibernate-orm · error · WrongClassException

Expected object of type `%s`, but found `%s`; discriminator

Error message

Expected object of type `%s`, but found `%s`; discriminator = %s

What it means

Error "Expected object of type `%s`, but found `%s`; discriminator = %s" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityConcreteTypeLoader.java:100

								RowTransformerStandardImpl.instance(),
								null,
								ListResultsConsumer.UniqueSemantic.NONE,
								1
						);

		if ( results.isEmpty() ) {
			throw new ObjectNotFoundException( entityDescriptor.getEntityName(), id );
		}
		else {
			assert results.size() == 1;
			final Object result = results.get( 0 );
			final var mappingMetamodel = factory.getMappingMetamodel();
			final var concreteType =
					result instanceof Class<?> concreteClass
							? mappingMetamodel.getEntityDescriptor( concreteClass )
							: mappingMetamodel.getEntityDescriptor( (String) result );
			if ( !concreteType.isTypeOrSuperType( entityDescriptor ) ) {
				throw new WrongClassException(
						concreteType.getEntityName(),
						id,
						entityDescriptor.getEntityName(),
						result
				);
			}
			return concreteType;
		}
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Check the discriminator values and inheritance mapping; the row's discriminator maps to a different subclass than requested.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/loader/ast/internal/EntityConcreteTypeLoader.java:100 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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