hibernate/hibernate-orm · error · MappingException

Association [ ] for entity [ ] references unmapped class [ ]

Error message

Association [%s] for entity [%s] references unmapped class [%s]

What it means

Second-pass failure for one-to-many collections: the referenced element entity name is absent from persistentClasses, so the OneToMany cannot be bound. The target entity class of the collection is not mapped in this persistence unit.

Solutions

  1. Map the referenced class as an entity (add @Entity and include it in the persistence unit).
  2. Or fix the association target to an already-mapped class.
Defensive patterns

Strategy: validation

When it happens

Trigger: An association or reference targets a type that Hibernate has not mapped as an entity.

Common situations: Missing @Entity on the target class, the class not being scanned into the persistence unit, or a typo in the entity name.


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

Appendix: source

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

	 */
	protected void bindOneToManySecondPass(Map<String, PersistentClass> persistentClasses) {
		if ( property == null ) {
			throw new AssertionFailure( "Null property" );
		}

		logOneToManySecondPass();

		final var oneToMany =
				new org.hibernate.mapping.OneToMany( buildingContext, getCollection().getOwner() );
		collection.setElement( oneToMany );
		oneToMany.setReferencedEntityName( getElementType().getName() );
		oneToMany.setNotFoundAction( notFoundAction );

		final String referencedEntityName = oneToMany.getReferencedEntityName();
		final var associatedClass = persistentClasses.get( referencedEntityName );
		handleJpaOrderBy( collection, associatedClass );
		if ( associatedClass == null ) {
			throw new MappingException(
					String.format( "Association [%s] for entity [%s] references unmapped class [%s]",
							propertyName, propertyHolder.getClassName(), referencedEntityName )
			);
		}
		oneToMany.setAssociatedClass( associatedClass );

		final var joins = getMetadataCollector().getJoins( referencedEntityName );
		foreignJoinColumns.setPropertyHolder( buildPropertyHolder(
				associatedClass,
				joins,
				foreignJoinColumns.getBuildingContext(),
				inheritanceStatePerClass
		) );
		foreignJoinColumns.setJoins( joins );
		final var collectionTable =
				foreignJoinColumns.hasMappedBy()
						? associatedClass.getRecursiveProperty( foreignJoinColumns.getMappedBy() )
								.getValue().getTable()

View on GitHub (pinned to fad1729dce)