quarkusio/quarkus · critical · IllegalStateException

No instance of %1$s was found for persistence unit %2$s. You

Error message

No instance of %1$s was found for persistence unit %2$s. You need to create an implementation for this interface to allow resolving the current tenant identifier.

What it means

When a Hibernate ORM persistence unit is configured for multi-tenancy (quarkus.hibernate.orm.multi_tenancy.enabled=true), Quarkus resolves the current tenant via a CDI bean implementing TenantResolver. This error is thrown at runtime when no such bean exists for the persistence unit, so the CurrentTenantIdentifierResolver cannot determine the tenant.

Source

Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/tenant/HibernateCurrentTenantIdentifierResolver.java:71

    @Override
    public boolean isRoot(String tenantId) {
        // Make sure that we're in a request
        if (!Arc.container().requestContext().isActive()) {
            return false;
        }
        TenantResolver resolver = tenantResolver(persistenceUnitName);
        if (resolver == null) {
            return false;
        }
        return resolver.isRoot(tenantId);
    }

    private static TenantResolver tenantResolver(String persistenceUnitName) {
        InjectableInstance<TenantResolver> instance = PersistenceUnitUtil.legacySingleExtensionInstanceForPersistenceUnit(
                TenantResolver.class, persistenceUnitName);
        if (instance.isUnsatisfied()) {
            throw new IllegalStateException(String.format(Locale.ROOT,
                    "No instance of %1$s was found for persistence unit %2$s. "
                            + "You need to create an implementation for this interface to allow resolving the current tenant identifier.",
                    TenantResolver.class.getSimpleName(), persistenceUnitName));
        }
        return instance.get();
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Create a CDI bean implementing TenantResolver and annotate it with @PersistenceUnitExtension for the target persistence unit
  2. Implement getDefaultTenantId()/resolveCurrentTenantIdentifier() to return a non-null tenant id
  3. Verify multi_tenancy.enabled=true is intentional; disable it if single-tenant
  4. Rebuild/restart so the bean is discovered by ArC

Example fix

// before
// no TenantResolver bean, multi-tenancy enabled -> IllegalStateException

// after
@PersistenceUnitExtension
@ApplicationScoped
public class MyTenantResolver implements TenantResolver {
    @Override
    public String getDefaultTenantId() {
        return CurrentRequestContext.getTenantId();
    }
}
Defensive patterns

Strategy: validation

Validate before calling

boolean hasTenantResolver = CDI.current().select(TenantResolver.class).isResolvable();
if (!hasTenantResolver && config.isMultiTenancyEnabled()) throw new IllegalStateException("Define a TenantResolver bean");

Type guard

boolean tenantResolverPresent() {
    return Arc.container() != null
        && !Arc.container().instance(TenantResolver.class).isUnsatisfied();
}

Try / catch

try {
    em.find(Entity.class, id);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("TenantResolver")) { failFast("Multi-tenancy misconfigured"); }
    throw e;
}

Prevention

When it happens

Trigger: Multi-tenancy is enabled for a persistence unit but no @PersistenceUnitExtension bean implementing io.quarkus.hibernate.orm.runtime.tenant.TenantResolver is registered; the first Hibernate operation that needs the tenant identifier calls HibernateCurrentTenantIdentifierResolver.tenantResolver(persistenceUnitName) and the CDI instance is unsatisfied.

Common situations: Enabling quarkus.hibernate.orm.multi_tenancy.enabled without writing a TenantResolver implementation; forgetting @PersistenceUnitExtension (or legacy quarkus scope) on the implementation; the bean not being a CDI bean (missing bean-defining annotation); using a persistence unit name with no tenant bean registered for it.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/1c5363c6b2fd5acf. Report an issue: GitHub.