hibernate/hibernate-orm · error · MappingException

@EnumeratedValue for EnumType.ORDINAL must be placed on a fi

Error message

@EnumeratedValue for EnumType.ORDINAL must be placed on a field whose type is byte, short, or int: %s.%s

What it means

Error "@EnumeratedValue for EnumType.ORDINAL must be placed on a field whose type is byte, short, or int: %s.%s" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/process/internal/InferredBasicValueResolver.java:496

			if ( !String.class.equals( fieldType )
					&& !char.class.equals( fieldType ) ) {
				throw new MappingException(
						String.format(
								Locale.ROOT,
								"@EnumeratedValue for EnumType.STRING must be placed on a field whose type is String or char: %s.%s",
								enumeratedValueField.getDeclaringClass().getName(),
								enumeratedValueField.getName()
						)
				);
			}
		}
		else {
			assert stdIndicators.getEnumeratedType() == null || stdIndicators.getEnumeratedType() == EnumType.ORDINAL;
			// JPA says only byte, short, or int are valid here
			if ( !byte.class.equals( fieldType )
					&& !short.class.equals( fieldType )
					&& !int.class.equals( fieldType ) ) {
				throw new MappingException(
						String.format(
								Locale.ROOT,
								"@EnumeratedValue for EnumType.ORDINAL must be placed on a field whose type is byte, short, or int: %s.%s",
								enumeratedValueField.getDeclaringClass().getName(),
								enumeratedValueField.getName()
						)
				);
			}
		}
	}

	public static <T> BasicValue.Resolution<T> fromTemporal(
			TemporalJavaType<T> reflectedJtd,
			BasicJavaType<?> explicitJavaType,
			JdbcType explicitJdbcType,
			Function<TypeConfiguration, MutabilityPlan<?>> explicitMutabilityPlanAccess,
			JdbcTypeIndicators stdIndicators) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Place @EnumeratedValue on a byte/short/int field of the enum, or switch the mapping to EnumType.STRING.

Example fix

Place @EnumeratedValue on a byte/short/int field of the enum, or switch the mapping to EnumType.STRING.

When it happens

Trigger: An entity mapping annotation or bootstrap configuration violates a Hibernate mapping rule.

Common situations: Annotation mapping mistakes: inverse-side @Id associations, @Column on @OneToOne, unmapped association targets, mismatched @EnumeratedValue/@Temporal usage, duplicate sequence generators.


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