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

Runtime mismatch detected by SequenceStyleGenerator when reconciling metadata: the entity mapping declares an increment size for a sequence that differs from the sequence's actual database increment size, and the configured mismatch strategy (EXCEPTION) forbids proceeding. FIX would adopt the DB value, NONE would ignore it.

Solutions

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

Strategy: validation

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.

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