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/LegacyHiLoAlgorithmOptimizer.java:122

				if ( state == null ) {
					state = createGenerationState();
					tenantSpecificState.put( tenantIdentifier, state );
				}
				return state;
			}
		}
	}

	private GenerationState createGenerationState() {
		final var state = new GenerationState();
		state.maxLo = initialMaxLo;
		state.lo = initialMaxLo + 1;
		return state;
	}

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

	@Override
	public Long getLastSourceValue() {
		lock.lock();
		try {
			return noTenantGenerationState().lastSourceValue;
		}
		finally {
			lock.unlock();
		}
	}

	@Override
	public boolean applyIncrementSizeToSourceValues() {
		return false;

View on GitHub (pinned to fad1729dce)

Solutions

  1. Ensure the sequence/table used by the legacy HiLo 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/83903d952ab5fa30. Report an issue: GitHub.