{"record":{"id":"70c3dcfcb7da3b76","repo":"quarkusio/quarkus","slug":"no-instance-of-1-s-was-found-for-persistence-unit-70c3dc","errorCode":null,"errorMessage":"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 connection.","messagePattern":"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 connection\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/tenant/HibernateMultiTenantConnectionProvider.java","lineNumber":88,"sourceCode":"        if (provider == null) {\n            final ConnectionProvider connectionProvider = resolveConnectionProvider(persistenceUnitName, tenantIdentifier);\n            providerMap.put(tenantIdentifier, connectionProvider);\n            return connectionProvider;\n        }\n        return provider;\n\n    }\n\n    private static ConnectionProvider resolveConnectionProvider(String persistenceUnitName, String tenantIdentifier) {\n        LOG.debugv(\"resolveConnectionProvider(persistenceUnitName={0}, tenantIdentifier={1})\", persistenceUnitName,\n                tenantIdentifier);\n        // TODO when we switch to the non-legacy method, don't forget to update the definition of the default bean\n        //   of type DataSourceTenantConnectionResolver (add the @PersistenceUnitExtension qualifier to that bean)\n        InjectableInstance<TenantConnectionResolver> instance = PersistenceUnitUtil\n                .legacySingleExtensionInstanceForPersistenceUnit(\n                        TenantConnectionResolver.class, persistenceUnitName);\n        if (instance.isUnsatisfied()) {\n            throw new IllegalStateException(\n                    String.format(\n                            Locale.ROOT, \"No instance of %1$s was found for persistence unit %2$s. \"\n                                    + \"You need to create an implementation for this interface to allow resolving the current tenant connection.\",\n                            TenantConnectionResolver.class.getSimpleName(), persistenceUnitName));\n        }\n        TenantConnectionResolver resolver = instance.get();\n        ConnectionProvider cp = resolver.resolve(tenantIdentifier);\n        if (cp == null) {\n            throw new IllegalStateException(\"Method 'TenantConnectionResolver.\"\n                    + \"resolve(String)' returned a null value. This violates the contract of the interface!\");\n        }\n        return cp;\n    }\n\n    /**\n     * Retrieves the tenant resolver or fails if it is not available.\n     *\n     * @return Current tenant resolver.","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/tenant/HibernateMultiTenantConnectionProvider.java#L70-L106","documentation":"For multi-tenant Hibernate ORM, each tenant connection is obtained from a CDI bean implementing TenantConnectionResolver. This error is thrown when no such bean is registered for the persistence unit, so HibernateMultiTenantConnectionProvider cannot resolve a ConnectionProvider.","triggerScenarios":"quarkus.hibernate.orm.multi_tenancy.enabled=true and an operation needs a tenant connection, but no @PersistenceUnitExtension bean implementing TenantConnectionResolver exists for the persistence unit; HibernateMultiTenantConnectionProvider.resolveConnectionProvider finds the CDI instance unsatisfied.","commonSituations":"Enabling multi-tenancy without a connection resolver; forgetting @PersistenceUnitExtension on the implementation; resolver bean defined in a library without bean discovery; typical with quarkus.hibernate.orm.datasource + DatabaseTenantConnectionResolver misuse (e.g., not exposing a bean for a schema-based strategy).","solutions":["Implement TenantConnectionResolver (e.g., extend DatabaseTenantConnectionResolver or SchemaTenantConnectionResolver) as a CDI bean","Annotate the bean with @PersistenceUnitExtension so it's linked to the persistence unit","Ensure each tenant has a corresponding configured datasource if using database-per-tenant","Confirm the bean archive includes the implementation (has a bean-defining annotation)"],"exampleFix":"// before\n// no TenantConnectionResolver bean -> IllegalStateException\n\n// after\n@PersistenceUnitExtension\n@ApplicationScoped\npublic class MyConnectionResolver implements TenantConnectionResolver {\n    @Override\n    public ConnectionProvider resolve(String tenantId) {\n        return databaseResolverFor(tenantId);\n    }\n}","handlingStrategy":"validation","validationCode":"boolean hasConnectionResolver = !Arc.container()\n    .instance(TenantConnectionResolver.class).isUnsatisfied();\nif (multiTenancyEnabled && !hasConnectionResolver) throw new IllegalStateException(\"Register a TenantConnectionResolver\");","typeGuard":"boolean connectionResolverPresent() {\n    return Arc.container() != null\n        && Arc.container().instance(TenantConnectionResolver.class).isResolvable();\n}","tryCatchPattern":"try {\n    return em.unwrap(SessionImplementor.class).getSessionFactory();\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"TenantConnectionResolver\")) { failFast(\"Missing connection resolver\"); }\n    throw e;\n}","preventionTips":["Ship TenantConnectionResolver together with TenantResolver in one multi-tenancy support module","Annotate both beans with @PersistenceUnitExtension for the right persistence unit","Verify each tenant's datasource exists in config at startup"],"tags":["hibernate-orm","multi-tenancy","cdi","missing-bean"],"backgroundTag":"missing-cdi-bean","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}