hibernate/hibernate-orm · error · AnnotationException

Annotation '%s' is not assignable to '%s'

Error message

Annotation '%s' is not assignable to '%s'

What it means

Error "Annotation '%s' is not assignable to '%s'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorAnnotationHelper.java:340

		}
		configurable.configure( creationContext, properties );
	}

	public static <A extends Annotation> void initializeGenerator(
			AnnotationBasedGenerator<A> generator,
			Annotation annotation,
			GeneratorCreationContext creationContext) {
		generator.initialize( castAnnotationType( annotation, generator), creationContext );
	}

	private static <A extends Annotation> A castAnnotationType(
			Annotation typeAnnotation,
			AnnotationBasedGenerator<A> annotationBased) {
		final var annotationType = annotationBased.getClass();
		Type[] typeArguments = GenericsHelper.typeArguments( AnnotationBasedGenerator.class, annotationType );
		if ( typeArguments.length > 0 && typeArguments[0] instanceof Class<?> annotationClass ) {
			if ( !annotationClass.isInstance( typeAnnotation ) ) {
				throw new AnnotationException( String.format( "Annotation '%s' is not assignable to '%s'",
						annotationType.getName(), annotationClass.getName() ) );
			}
			@SuppressWarnings("unchecked") // safe, we just checked it
			final var castAnnotation = (A) typeAnnotation;
			return castAnnotation;
		}
		throw new AssertionFailure( "Could not find implementing interface" );
	}

	public static void handleUuidStrategy(
			SimpleValue idValue,
			MemberDetails idMember,
			ClassDetails entityClass,
			MetadataBuildingContext context) {
		final var generatorConfig = findLocalizedMatch(
				HibernateAnnotations.UUID_GENERATOR,
				idMember,
				entityClass,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use an annotation type assignable to the expected generator annotation type.

When it happens

Trigger: A generator-related annotation is not assignable to the expected annotation type.

Common situations: Custom generator meta-annotations wired to an incompatible annotation type.


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