hibernate/hibernate-orm · error · ClassCastException

{} incompatible with {}

Error message

{} incompatible with {}

What it means

Error "{} incompatible with {}" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/proxy/pojo/bytebuddy/ByteBuddyInterceptor.java:50

			SharedSessionContractImplementor session,
			boolean overridesEquals) {
		super( entityName, persistentClass, id, getIdentifierMethod, setIdentifierMethod, componentIdType, session, overridesEquals );
		this.interfaces = interfaces;
	}

	@Override
	public Object intercept(Object proxy, Method method, Object[] args) throws Throwable {
		return invoke( method, args, proxy );
	}

	@Override
	protected Object call(Object proxy, Method method, Object[] args) throws Throwable {
		final Object target = getImplementation();
		final Object returnValue;
		try {
			if ( isPublic( persistentClass, method ) ) {
				if ( !method.getDeclaringClass().isInstance( target ) ) {
					throw new ClassCastException(
							target.getClass().getName()
							+ " incompatible with "
							+ method.getDeclaringClass().getName()
					);
				}
				returnValue = method.invoke( target, args );
			}
			else {
				method.setAccessible( true );
				returnValue = method.invoke( target, args );
			}

			if ( returnValue == target ) {
				final var returnValueClass = returnValue.getClass();
				if ( returnValueClass.isInstance( proxy ) ) {
					return proxy;
				}
				else {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Ensure the interceptor's entity class matches the proxy's persistent class.
  2. Avoid mixing proxies created for different entity mappings.

When it happens

Trigger: A runtime precondition of the Hibernate API is violated.

Common situations: Occurs when application code or configuration does not satisfy the documented contract of the API being called.


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