hibernate/hibernate-orm · error · DuplicateSecondaryTableException

Table with that name

Error message

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

What it means

DuplicateSecondaryTableException guard in addSecondaryTable: the entity already has a secondary table registered whose logical qualified name collides with the one being added (or matches the primary table). The same secondary table cannot be joined twice for one entity.

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.
Defensive patterns

Strategy: validation

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.

Appendix: 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)