hibernate/hibernate-orm · error · ClassCastException

Object of type '{}' can't be cast to CompositeTracker

Error message

Object of type '{}' can't be cast to CompositeTracker

What it means

Error "Object of type '{}' can't be cast to CompositeTracker" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java:323

		throw new ClassCastException( "Object of type '" + entity.getClass() + "' can't be cast to ManagedEntity" );
	}

	/**
	 * Cast the object to CompositeTracker
	 * (using this is highly preferrable over a direct cast)
	 * @param entity the entity to cast
	 * @return the same instance after casting
	 * @throws ClassCastException if it's not of the right type
	 */
	public static CompositeTracker asCompositeTracker(final Object entity) {
		Objects.requireNonNull( entity );
		if ( entity instanceof PrimeAmongSecondarySupertypes t ) {
			final CompositeTracker e = t.asCompositeTracker();
			if ( e != null ) {
				return e;
			}
		}
		throw new ClassCastException( "Object of type '" + entity.getClass() + "' can't be cast to CompositeTracker" );
	}

	/**
	 * Cast the object to CompositeOwner
	 * (using this is highly preferrable over a direct cast)
	 * @param entity the entity to cast
	 * @return the same instance after casting
	 * @throws ClassCastException if it's not of the right type
	 */
	public static CompositeOwner asCompositeOwner(final Object entity) {
		Objects.requireNonNull( entity );
		if ( entity instanceof PrimeAmongSecondarySupertypes t ) {
			final CompositeOwner e = t.asCompositeOwner();
			if ( e != null ) {
				return e;
			}
		}
		throw new ClassCastException( "Object of type '" + entity.getClass() + "' can't be cast to CompositeOwner" );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Ensure the embeddable/composite type is bytecode-enhanced so it implements CompositeTracker
  2. Check with instanceof CompositeTracker before casting

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java:323 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/df0ad44e69f37116. Report an issue: GitHub.