{"record":{"id":"65379a0f7f988769","repo":"quarkusio/quarkus","slug":"multiple-instances-of-1-s-were-found-for-hibernat","errorCode":null,"errorMessage":"Multiple instances of %1$s were found for Hibernate Search index %2$s in persistence unit %3$s. At most one instance can be assigned to each index. Instances found: %4$s","messagePattern":"Multiple instances of %1\\$s were found for Hibernate Search index %2\\$s in persistence unit %3\\$s\\. At most one instance can be assigned to each index\\. Instances found: %4\\$s","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java","lineNumber":34,"sourceCode":"public final class HibernateSearchBeanUtil {\n\n    private HibernateSearchBeanUtil() {\n    }\n\n    public static <T> Optional<BeanReference<T>> singleExtensionBeanReferenceFor(Optional<String> override, Class<T> beanType,\n            String persistenceUnitName, String backendName, String indexName) {\n        return override.map(string -> BeanReference.parse(beanType, string))\n                .or(() -> singleExtensionBeanReferenceFor(beanType, persistenceUnitName, backendName, indexName));\n    }\n\n    private static <T> Optional<BeanReference<T>> singleExtensionBeanReferenceFor(Class<T> beanType,\n            String persistenceUnitName, String backendName, String indexName) {\n        InjectableInstance<T> instance = extensionInstanceFor(beanType, persistenceUnitName, 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 index %2$s in persistence unit %3$s.\"\n                                + \" At most one instance can be assigned to each index. Instances found: %4$s\",\n                        beanType.getSimpleName(), indexName, persistenceUnitName, 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 backend %2$s in persistence unit %3$s.\"\n                                + \" At most one instance can be assigned to each backend. Instances found: %4$s\",\n                        beanType.getSimpleName(), backendName, persistenceUnitName, ambiguousClassNames));\n            } else {\n                throw new IllegalStateException(String.format(Locale.ROOT,\n                        \"Multiple instances of %1$s were found for Hibernate Search in persistence unit %2$s.\"\n                                + \" At most one instance can be assigned to each persistence unit. Instances found: %3$s\",\n                        beanType.getSimpleName(), persistenceUnitName, ambiguousClassNames));\n            }\n        }\n        return instance.isResolvable() ? Optional.of(new ArcBeanReference<>(instance.getHandle().getBean())) : Optional.empty();\n    }\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-search-orm-elasticsearch/runtime/src/main/java/io/quarkus/hibernate/search/orm/elasticsearch/runtime/bean/HibernateSearchBeanUtil.java#L16-L52","documentation":"Quarkus's Hibernate Search ORM Elasticsearch extension resolves exactly one CDI bean for a given Hibernate Search index (e.g. an ElasticsearchIndexManager or similar bean type) within a persistence unit. When CDI's InjectableInstance is ambiguous — more than one bean matches the required type and qualifiers for that index — the extension cannot pick one and throws this IllegalStateException from HibernateSearchBeanUtil.singleExtensionBeanReferenceFor. The error lists the bean classes that were found so you can remove or disambiguate them.","triggerScenarios":"Calling singleExtensionBeanReferenceFor with a non-null indexName where extensionInstanceFor(...) resolves an InjectableInstance whose isAmbiguous() is true — i.e. two or more CDI beans of the requested type (with the same qualifiers) are visible in the persistence unit and assigned to the same index. Typical API path: application code or internal boot code requesting a single bean reference via HibernateSearchBeanUtil during Hibernate Search initialization.","commonSituations":"Declaring two custom beans (e.g. two @SearchExtension-annotated beans such as two PropertyBridge or EntityLoadingContext beans of the same type) targeting the same named index; accidentally registering the same bean in both application and a test @Produces; copying a bean class into two packages so both are discovered; using @DefaultBean plus your own override without correct qualifiers for the index.","solutions":["Identify the duplicate classes listed in the message ('Instances found: [A, B]') and delete or de-register one of them.","Make the unwanted bean not match the index by changing/removing its @SearchExtension qualifier (e.g. different backend/index name) or annotate it with @Alternative/@Priority so only one is selected.","If the duplicate comes from a library/test fixture, exclude it via @QuarkusTestProfile or a CDI @Exclude/veto so it is not discovered in production.","Ensure you are not accidentally producing the same bean twice (e.g. a @Produces method plus a class-level @SearchExtension on the same type)."],"exampleFix":"// before: two beans for the same index\n@SearchExtension(backend = \"default\", index = \"Books\")\npublic class MyBridgeA implements PropertyBridge<Book> { ... }\n@SearchExtension(backend = \"default\", index = \"Books\")\npublic class MyBridgeB implements PropertyBridge<Book> { ... }\n\n// after: only one bean assigned to the index\n@SearchExtension(backend = \"default\", index = \"Books\")\npublic class MyBridgeA implements PropertyBridge<Book> { ... }\n// MyBridgeB removed, or given a different index/backend qualifier","handlingStrategy":"validation","validationCode":"// Before startup, assert exactly one bean targets each index:\nSet<String> indexBeans = Arc.container().instance(Object.class)\n    .selectWithQualifier(new SearchExtensionQualifier(\"default\", \"Books\"))\n    .handlesStream().map(h -> h.getBean().getBeanClass().getName())\n    .collect(Collectors.toSet());\nif (indexBeans.size() > 1) {\n    throw new IllegalStateException(\"Duplicate index beans: \" + indexBeans);\n}","typeGuard":null,"tryCatchPattern":"try {\n    hibernateSearchBooter.start();\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Multiple instances of\")) {\n        LOGGER.error(\"Duplicate @SearchExtension beans; keep one per index: \" + e.getMessage());\n    }\n    throw e;\n}","preventionTips":["One @SearchExtension bean per (backend, index) target; use qualifiers to disambiguate.","Grep your codebase for duplicate @SearchExtension annotations with identical backend/index values before building.","Mark override beans @Alternative with @Priority instead of adding siblings to @DefaultBean."],"tags":["quarkus","cdi","hibernate-search","elasticsearch","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"}