hibernate/hibernate-orm · error · IllegalArgumentException

Given value '%s' did not match expected identifier type '%s'

Error message

Given value '%s' did not match expected identifier type '%s' of entity '%s'

What it means

Error "Given value '%s' did not match expected identifier type '%s' of entity '%s'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java:38

import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.java.CoercionException;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Steve Ebersole
 */
public class Helper {
	public static final FindOption[] NO_OPTIONS = new FindOption[0];

	public static Object coerceId(EntityPersister entityPersister, Object id, SessionFactoryImplementor factory) {
		final var identifierMapping = entityPersister.getIdentifierMapping();
		if ( isLoadByIdComplianceEnabled( factory ) ) {
			final var javaType = identifierMapping.getJavaType();
			if ( !identifierMapping.isVirtual() && !javaType.isInstance( id ) ) {
				// per expectation of EntityHandler#find / EntityHandler#get
				throw new IllegalArgumentException(
						"Given value '%s' did not match expected identifier type '%s' of entity '%s'"
								.formatted( id, javaType.getTypeName(), entityPersister.getEntityName() ) );
			}
			return id;
		}
		else {
			try {
				return identifierMapping.isVirtual()
						? id // special case for a class with an @IdClass
						: identifierMapping.getJavaType().coerce( id );
			}
			catch ( Exception e ) {
				throw new IllegalArgumentException(
						"Argument '%s' could not be converted to the identifier type of entity '%s': %s"
								.formatted( id, entityPersister.getEntityName(), e.getMessage() ),
						e
				);
			}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Pass an id of the entity's declared identifier type (e.g. Long vs Integer); convert the value before calling find.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/internal/find/Helper.java:38 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/9615dd82d7e2bcae. Report an issue: GitHub.