hibernate/hibernate-orm · error · AnnotationException

Both sides of the bidirectional association '" +…

Error message

Both sides of the bidirectional association '" + associatedClass.getEntityName() + "." + mappedByProperty + "' specify 'mappedBy'

What it means

Bidirectionality guard in TableBinder: while linking a mappedBy association, both sides of the association turn out to specify mappedBy (each declares itself the inverse). Neither side owns the join, so no join columns can be determined.

Solutions

  1. Remove mappedBy from one side of the bidirectional association so only one side is unowned.
Defensive patterns

Strategy: validation

When it happens

Trigger: An association declares 'mappedBy' naming a property that does not exist, has the wrong type, or is not the owning side on the target entity.

Common situations: Bidirectional associations where mappedBy is misspelled, both sides claim ownership, or the target entity was refactored without updating the mapping.


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

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java:860

			AnnotatedJoinColumns joinColumns,
			SimpleValue value,
			PersistentClass associatedClass,
			String mappedByProperty) {
		final var firstColumn = joinColumns.getJoinColumns().get(0);
		for ( var selectable: mappedByColumns( associatedClass, mappedByProperty ) ) {
			if ( selectable instanceof Column column ) {
				firstColumn.overrideFromReferencedColumnIfNecessary( column );
			}
			firstColumn.linkValueUsingCopy( selectable, value );
		}
	}

	private static List<Selectable> mappedByColumns(PersistentClass associatedClass, String mappedByProperty) {
		final var value = associatedClass.getRecursiveProperty( mappedByProperty ).getValue();
		if ( value instanceof Collection collection ) {
			final var element = collection.getElement();
			if ( element == null ) {
				throw new AnnotationException( "Both sides of the bidirectional association '"
						+ associatedClass.getEntityName() + "." + mappedByProperty + "' specify 'mappedBy'" );
			}
			return element.getSelectables();
		}
		else if ( value instanceof Any any ) {
			return any.getKeyDescriptor().getSelectables();
		}
		else {
			return value.getSelectables();
		}
	}

	public static void linkJoinColumnWithValueOverridingNameIfImplicit(
			PersistentClass referencedEntity,
			Value value,
			AnnotatedJoinColumns joinColumns,
			SimpleValue simpleValue) {
		final var valueColumns = value.getColumns();

View on GitHub (pinned to fad1729dce)