hibernate/hibernate-orm · error · HibernateException

Resolving id to natural id returned more that one row: %s #%

Error message

Resolving id to natural id returned more that one row: %s #%s

What it means

Error "Resolving id to natural id returned more that one row: %s #%s" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java:365

		final List<?> results =
				factory.getJdbcServices().getJdbcSelectExecutor()
						.list(
								createJdbcOperationQuerySelect( sqlSelect, factory, bindings, QueryOptions.NONE ),
								bindings,
								new NoCallbackExecutionContext( session ),
								// because we select the natural id,
								// we want to "reduce" the result
								RowTransformerSingularReturnImpl.instance(),
								null,
								ListResultsConsumer.UniqueSemantic.FILTER,
								1
						);

		return switch ( results.size() ) {
			case 0 -> null;
			case 1 -> results.get( 0 );
			default -> throw new HibernateException(
					String.format(
							"Resolving id to natural id returned more that one row: %s #%s",
							entityDescriptor().getEntityName(),
							id
					)
			);
		};
	}

	void applyRestriction(
			TableGroup rootTableGroup,
			Consumer<Predicate> predicateConsumer,
			BiConsumer<JdbcParameter, JdbcParameterBinding> jdbcParameterConsumer,
			Object jdbcValue,
			SelectableMapping jdbcValueMapping,
			SqlExpressionResolver expressionResolver) {
		final var columnReference =
				resolveColumnReference( rootTableGroup, jdbcValueMapping, expressionResolver );

View on GitHub (pinned to fad1729dce)

Solutions

  1. Fix duplicate rows for the natural id; enforce uniqueness on the natural id columns.

When it happens

Trigger: Thrown at hibernate-core/src/main/java/org/hibernate/loader/ast/internal/AbstractNaturalIdLoader.java:365 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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