hibernate/hibernate-orm · error · AnnotationException

Association '<role>' is a '@ManyToAny' and must specify a '@

Error message

Association '<role>' is a '@ManyToAny' and must specify a '@JoinTable'

What it means

Error "Association '<role>' is a '@ManyToAny' and must specify a '@JoinTable'" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java:2623

					+ " is an unowned collection and may not be annotated '@Check'" );
		}
	}

	private void detectManyToManyProblems(
			TypeDetails elementType,
			boolean isCollectionOfEntities,
			boolean isManyToAny) {

		if ( !isCollectionOfEntities) {
			if ( property.hasDirectAnnotationUsage( ManyToMany.class )
					|| property.hasDirectAnnotationUsage( OneToMany.class ) ) {
				throw new AnnotationException( "Association '" + safeCollectionRole() + "'"
						+ targetEntityMessage( elementType ) );
			}
			else if (isManyToAny) {
				final var joinTable = propertyHolder.getJoinTable( property );
				if ( joinTable == null ) {
					throw new AnnotationException( "Association '" + safeCollectionRole()
							+ "' is a '@ManyToAny' and must specify a '@JoinTable'" );
				}
			}
			else {
				final var joinTableAnn = propertyHolder.getJoinTable( property );
				if ( joinTableAnn != null && !ArrayHelper.isEmpty( joinTableAnn.inverseJoinColumns() ) ) {
					throw new AnnotationException( "Association '" + safeCollectionRole()
							+ " has a '@JoinTable' with 'inverseJoinColumns' and"
							+ targetEntityMessage( elementType ) );
				}
			}
		}
	}

	static String targetEntityMessage(TypeDetails elementType) {
		final String problem =
				isEntity( elementType.determineRawClass() )
						? " which does not belong to the same persistence unit"

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add a @JoinTable to the @ManyToAny association 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/3055a435eaa42f6e. Report an issue: GitHub.