hibernate/hibernate-orm · error · AnnotationException

Identifier attribute '%s' has too many generator annotations

Error message

Identifier attribute '%s' has too many generator annotations: %s

What it means

Error "Identifier attribute '%s' has too many generator annotations: %s" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java:845

	static void createIdGeneratorsFromGeneratorAnnotations(
			PropertyHolder propertyHolder,
			PropertyData inferredData,
			SimpleValue idValue,
			MetadataBuildingContext buildingContext) {
		final var modelsContext = buildingContext.getBootstrapContext().getModelsContext();
		final var idMemberDetails = inferredData.getAttributeMember();
		final var idGeneratorAnnotations = idMemberDetails.getMetaAnnotated( IdGeneratorType.class, modelsContext );
		final var generatorAnnotations = idMemberDetails.getMetaAnnotated( ValueGenerationType.class, modelsContext );
		// Since these collections may contain proxies created by common-annotations module, we cannot reliably use
		// simple remove/removeAll collection methods as those proxies do not implement hashcode/equals and even a
		// simple 'a.equals(a)' will return 'false'. Instead, we will check the annotation types. Since generator
		// annotations should not be "repeatable", we should have only at most one annotation for a generator.
		for ( var id : idGeneratorAnnotations ) {
			generatorAnnotations.removeIf( gen -> gen.annotationType().equals( id.annotationType() ) );
		}

		if ( idGeneratorAnnotations.size() + generatorAnnotations.size() > 1 ) {
			throw new AnnotationException( String.format(
					Locale.ROOT,
					"Identifier attribute '%s' has too many generator annotations: %s",
					getPath( propertyHolder, inferredData ),
					combineUntyped( idGeneratorAnnotations, generatorAnnotations )
			) );
		}
		if ( !idGeneratorAnnotations.isEmpty() ) {
			idValue.setCustomIdGeneratorCreator( identifierGeneratorCreator(
					idMemberDetails,
					idGeneratorAnnotations.get(0),
					idValue,
					beanContainer( buildingContext )
			) );
		}
		else if ( !generatorAnnotations.isEmpty() ) {
//			idValue.setCustomGeneratorCreator( generatorCreator( idMemberDetails, generatorAnnotation ) );
			throw new AnnotationException( String.format(
					Locale.ROOT,

View on GitHub (pinned to fad1729dce)

Solutions

  1. Keep only one generator annotation on the identifier attribute.

When it happens

Trigger: An identifier/value generator declaration is inconsistent with the referenced generator or the annotated element.

Common situations: @GeneratedValue pointing at a generator of the wrong kind (SEQUENCE vs TABLE), a missing named generator, too many generator annotations, or an unsupported generation strategy for @CollectionId.


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