hibernate/hibernate-orm · error · MappingException

Could not determine key type for '@Any' mapping (specify '@A

Error message

Could not determine key type for '@Any' mapping (specify '@AnyKeyJavaType' or '@AnyKeyJavaClass')

What it means

Error "Could not determine key type for '@Any' mapping (specify '@AnyKeyJavaType' or '@AnyKeyJavaClass')" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java:886

								.resolveDescriptor( anyKeyJavaClass.value() );
			}

			// mainly used in XML interpretation
			final var anyKeyType = member.locateAnnotationUsage( AnyKeyType.class, context );
			if ( anyKeyType != null ) {
				final String namedType = anyKeyType.value();
				final var registeredType =
						typeConfiguration.getBasicTypeRegistry()
								.getRegisteredType( namedType );
				if ( registeredType == null ) {
					throw new MappingException( "Unrecognized @AnyKeyType value - " + namedType );
				}
				else {
					return (BasicJavaType<?>) registeredType.getJavaTypeDescriptor();
				}
			}

			throw new MappingException("Could not determine key type for '@Any' mapping (specify '@AnyKeyJavaType' or '@AnyKeyJavaClass')");
		};

		explicitJdbcTypeAccess = typeConfiguration -> {
			final var anyKeyJdbcType = member.locateAnnotationUsage( AnyKeyJdbcType.class, context );
			if ( anyKeyJdbcType != null ) {
				final var jdbcTypeClass = anyKeyJdbcType.value();
				if ( jdbcTypeClass != null ) {
					return useDeferredBeanContainerAccess
							? FallbackBeanInstanceProducer.INSTANCE.produceBeanInstance( jdbcTypeClass )
							: getManagedBeanRegistry().getBean( jdbcTypeClass ).getBeanInstance();
				}
			}

			final var anyKeyJdbcTypeCode = member.locateAnnotationUsage( AnyKeyJdbcTypeCode.class, context );
			if ( anyKeyJdbcTypeCode != null ) {
				final int code = anyKeyJdbcTypeCode.value();
				if ( code != Integer.MIN_VALUE ) {
					return getDescriptor( typeConfiguration, code );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Specify the key type explicitly with @AnyKeyJavaType or @AnyKeyJavaClass on the @Any mapping.

When it happens

Trigger: An @Any/@ManyToAny mapping is missing required key-type or join information.

Common situations: Polymorphic @Any associations without @AnyKeyJavaType/@AnyKeyJavaClass, without any @JoinColumn, or with an unrecognized @AnyKeyType value.


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