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/HiLoOptimizer.java:155

				tenantSpecificState = new ConcurrentHashMap<>();
				final var state = new GenerationState();
				tenantSpecificState.put( tenantId, state );
				return state;
			}
			else {
				var state = tenantSpecificState.get( tenantId );
				if ( state == null ) {
					state = new GenerationState();
					tenantSpecificState.put( tenantId, state );
				}
				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 HiLo optimizer exists and is initialized for the no-tenant context.
  2. Check multitenancy configuration if tenants are in use.

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/a02e6bf30636f8b2. Report an issue: GitHub.