hibernate/hibernate-orm · error · MappingException

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

Error message

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

What it means

Validation of an @EnumeratedValue field on an enum mapped with EnumType.ORDINAL (the default): the annotated field is not byte, short, or int as JPA requires for ordinal enum value extraction. The field's declared type must be one of those integral types.

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.
Defensive patterns

Strategy: validation

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.

Appendix: 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)