hibernate/hibernate-orm · error · DuplicateSecondaryTableException

Table with that name [%s] already associated with entity

Error message

Table with that name [%s] already associated with entity

What it means

Error "Table with that name [%s] already associated with entity" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java:1486

					);
				}
			}
		}

		@Override
		public void addSecondaryTable(QualifiedTableName logicalQualifiedTableName, Join secondaryTableJoin) {
			final Identifier tableName = logicalQualifiedTableName.getTableName();

			if ( Identifier.areEqual(
				toIdentifier(
					new QualifiedTableName(
						toIdentifier( primaryTable.getCatalog() ),
						toIdentifier( primaryTable.getSchema() ),
						primaryTableLogicalName
					).render()
				),
				toIdentifier( logicalQualifiedTableName.render() ) ) ) {
				throw new DuplicateSecondaryTableException( tableName );
			}

			if ( secondaryTableJoinMap == null ) {
				//secondaryTableJoinMap = new HashMap<Identifier,Join>();
				//secondaryTableJoinMap.put( logicalName, secondaryTableJoin );
				secondaryTableJoinMap = new HashMap<>();
				secondaryTableJoinMap.put( tableName.getCanonicalName(), secondaryTableJoin );
			}
			else {
				//final Join existing = secondaryTableJoinMap.put( logicalName, secondaryTableJoin );
				final Join existing =
						secondaryTableJoinMap.put( tableName.getCanonicalName(), secondaryTableJoin );
				if ( existing != null ) {
					throw new DuplicateSecondaryTableException( tableName );
				}
			}
		}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Remove the duplicate table binding; each table name can be associated with an entity only once (check @SecondaryTable and @Table definitions).
  2. Rename one of the conflicting table declarations if two distinct tables were intended.
  3. Check for duplicate mapping of the same class via both annotations and hbm.xml.

When it happens

Trigger: The same table name is bound twice to an entity's secondary/primary tables.

Common situations: Declaring a @SecondaryTable whose name collides with the primary table or another secondary table of the entity.


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