hibernate/hibernate-orm · error · IllegalStateException

Could not locate previous generation state for no-tenant

Error message

Could not locate previous generation state for no-tenant

What it means

Error "Could not locate previous generation state for no-tenant" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/id/enhanced/PooledOptimizer.java:155

			return assignNewStateToTenant( tenantIdentifier );
		}
		else {
			final var state = tenantSpecificState.get( tenantIdentifier );
			return state == null
					? assignNewStateToTenant( tenantIdentifier )
					: state;
		}
	}

	private GenerationState assignNewStateToTenant(String tenantIdentifier) {
		final var newState = new GenerationState();
		tenantSpecificState.put( tenantIdentifier, newState );
		return newState;
	}

	private GenerationState noTenantGenerationState() {
		if ( noTenantState == null ) {
			throw new IllegalStateException( "Could not locate previous generation state for no-tenant" );
		}
		return noTenantState;
	}

	@Override
	public Long getLastSourceValue() {
		return noTenantGenerationState().hiValue;
	}

	@Override
	public boolean applyIncrementSizeToSourceValues() {
		return true;
	}

	/**
	 * Getter for property 'lastValue'.
	 * <p>
	 * Exposure intended for testing purposes.

View on GitHub (pinned to fad1729dce)

Solutions

  1. Ensure the sequence/table used by the pooled optimizer exists and is initialized for the no-tenant context.

When it happens

Trigger: Thrown when an identifier optimizer cannot find its previous generation state after the no-tenant state was cleaned up or reset.

Common situations: Typical situations: concurrent id generation while the SessionFactory is shutting down; custom tenant handling that clears the optimizer state; race conditions during schema export.


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