hibernate/hibernate-orm · error · IllegalArgumentException

Cached version was not of type {type.getName()}

Error message

Cached version was not of type {type.getName()}

What it means

Error "Cached version was not of type {type.getName()}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/cache/cfg/internal/ComparatorUtil.java:24

import jakarta.annotation.Nonnull;
import org.hibernate.type.BasicType;

import java.util.Comparator;

class ComparatorUtil {
	@Nonnull
	static <T> Comparator<Object> versionComparator(BasicType<T> type) {
		return (u, v) -> {
			final var descriptor = type.getJavaTypeDescriptor();
			final T x;
			final T y;
			try {
				x = descriptor.cast( u );
				y = descriptor.cast( v );
			}
			catch (Exception e) {
				throw new IllegalArgumentException( "Cached version was not of type " + type.getName(), e );
			}
			return descriptor.getComparator().compare( x, y );
		};
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use a consistent version property type (@Version Long/Integer/Timestamp) for the cached entity; mixed versions break cache entry comparison.

Example fix

Use a consistent version property type (@Version Long/Integer/Timestamp) for the cached entity; mixed versions break cache entry comparison.

When it happens

Trigger: Second-level caching is misconfigured or a cache region/key does not match what Hibernate expects.

Common situations: Enabling @Cacheable entities without setting hibernate.cache.region.factory_class, custom RegionFactory implementations, or unwrapping Cache to provider types.


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