{"record":{"id":"d5406b8cd215b71f","repo":"quarkusio/quarkus","slug":"multiple-instances-of-1-s-were-found-for-hibernat-d5406b","errorCode":null,"errorMessage":"Multiple instances of %1$s were found for Hibernate Search Standalone backend %2$s. At most one instance can be assigned to each backend. Instances found: %3$s","messagePattern":"Multiple instances of %1\\$s were found for Hibernate Search Standalone backend %2\\$s\\. At most one instance can be assigned to each backend\\. Instances found: %3\\$s","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java","lineNumber":39,"sourceCode":"    public static <T> Optional<BeanReference<T>> singleExtensionBeanReferenceFor(Optional<String> override, Class<T> beanType,\n            String backendName, String indexName) {\n        return override.map(string -> BeanReference.parse(beanType, string))\n                .or(() -> singleExtensionBeanReferenceFor(beanType, backendName, indexName));\n    }\n\n    private static <T> Optional<BeanReference<T>> singleExtensionBeanReferenceFor(Class<T> beanType,\n            String backendName, String indexName) {\n        InjectableInstance<T> instance = extensionInstanceFor(beanType, backendName, indexName);\n        if (instance.isAmbiguous()) {\n            List<String> ambiguousClassNames = instance.handlesStream().map(h -> h.getBean().getBeanClass().getCanonicalName())\n                    .toList();\n            if (indexName != null) {\n                throw new IllegalStateException(String.format(Locale.ROOT,\n                        \"Multiple instances of %1$s were found for Hibernate Search Standalone index %2$s.\"\n                                + \" At most one instance can be assigned to each index. Instances found: %3$s\",\n                        beanType.getSimpleName(), indexName, ambiguousClassNames));\n            } else if (backendName != null) {\n                throw new IllegalStateException(String.format(Locale.ROOT,\n                        \"Multiple instances of %1$s were found for Hibernate Search Standalone backend %2$s.\"\n                                + \" At most one instance can be assigned to each backend. Instances found: %3$s\",\n                        beanType.getSimpleName(), backendName, ambiguousClassNames));\n            } else {\n                throw new IllegalStateException(String.format(Locale.ROOT,\n                        \"Multiple instances of %1$s were found for Hibernate Search Standalone.\"\n                                + \" At most one instance can be assigned. Instances found: %2$s\",\n                        beanType.getSimpleName(), ambiguousClassNames));\n            }\n        }\n        return instance.isResolvable() ? Optional.of(new ArcBeanReference<>(instance.getHandle().getBean())) : Optional.empty();\n    }\n\n    public static <T> Optional<List<BeanReference<T>>> multiExtensionBeanReferencesFor(Optional<List<String>> override,\n            Class<T> beanType,\n            String backendName, String indexName) {\n        return override.map(strings -> strings.stream()\n                .map(string -> BeanReference.parse(beanType, string))","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-search-standalone-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/standalone/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java#L21-L57","documentation":"Same resolution logic as the index-scope variant: singleExtensionBeanReferenceFor() found multiple beans of the requested type whose qualifiers map to the same backend (backendName != null, indexName == null). Since at most one bean may be assigned per backend, the util throws IllegalStateException with the conflicting bean class names.","triggerScenarios":"Two or more beans of beanType are annotated @HibernateSearchExtension(...) targeting the same backend (e.g. backend = \"elasticsearch\") without an index restriction, making the backend-scoped lookup ambiguous.","commonSituations":"Providing two backend-level customizations (e.g. two HttpClientFactory or two entity loader implementations) for one named backend; one bean intended for a different backend configured with the wrong backend name; leftover bean from a copy-paste.","solutions":["Delete one of the conflicting backend-scoped beans listed in 'Instances found'.","Restrict each bean to a narrower scope (add index = ...) or move one to another backend name so only one bean matches per backend.","Change the backend attribute on the beans' @HibernateSearchExtension annotation so they target different backends.","If a built-in extension bean conflicts with yours, check the docs for the config property that disables/exposes the built-in one."],"exampleFix":"// before: two backend-wide beans for the same backend\n@HibernateSearchExtension(backend = \"elasticsearch\")\n@ApplicationScoped public class ClientA implements HttpClientFactory { ... }\n@HibernateSearchExtension(backend = \"elasticsearch\")\n@ApplicationScoped public class ClientB implements HttpClientFactory { ... }\n\n// after: only one backend-wide bean remains\n@HibernateSearchExtension(backend = \"elasticsearch\")\n@ApplicationScoped public class ClientA implements HttpClientFactory { ... }","handlingStrategy":"validation","validationCode":"// Backend-scoped ambiguity check before startup finishes\nInjectableInstance<MyType> i = Arc.container().select(MyType.class, backendQualifier);\nif (i.isAmbiguous()) {\n    throw new IllegalStateException(\"Multiple backend-level beans for backend 'elasticsearch'\");\n}","typeGuard":"public static <T> boolean hasSingleBackendBean(Class<T> type, Annotation... qualifiers) {\n    var instance = Arc.container().select(type, qualifiers);\n    return instance.isResolvable() && !instance.isAmbiguous();\n}","tryCatchPattern":"try {\n    Optional<BeanReference<T>> ref = HibernateSearchBeanUtil.singleExtensionBeanReferenceFor(beanType, backendName, null);\n} catch (IllegalStateException e) {\n    log.errorf(\"Backend '%s' has multiple candidate beans — remove or re-qualify one\", backendName, e);\n}","preventionTips":["Only one backend-wide bean per role per backend name — scope extras with index = ....","Check backend attribute values in @HibernateSearchExtension for typos that accidentally collide.","Delete leftover/alternative implementations when replacing a customization.","Read the listed bean class names in the exception to locate the conflict quickly."],"tags":["cdi","quarkus","hibernate-search","ambiguous-bean"],"backgroundTag":"ambiguous-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"}