{"record":{"id":"e6b583b9109f48c3","repo":"hibernate/hibernate-orm","slug":"multiple-active-metadatabuilder-definitions-were-d","errorCode":null,"errorMessage":"Multiple active MetadataBuilder definitions were discovered : <activeFactoryNames>","messagePattern":"Multiple active MetadataBuilder definitions were discovered : <activeFactoryNames>","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java","lineNumber":203,"sourceCode":"\t\t\t\t\t\t.loadJavaServices( MetadataBuilderFactory.class );\n\n\t\tMetadataBuilder builder = null;\n\t\tList<String> activeFactoryNames = null;\n\n\t\tfor ( MetadataBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories) {\n\t\t\tfinal MetadataBuilder returnedBuilder =\n\t\t\t\t\tdiscoveredBuilderFactory.getMetadataBuilder( this, defaultBuilder );\n\t\t\tif ( returnedBuilder != null ) {\n\t\t\t\tif ( activeFactoryNames == null ) {\n\t\t\t\t\tactiveFactoryNames = new ArrayList<>();\n\t\t\t\t}\n\t\t\t\tactiveFactoryNames.add( discoveredBuilderFactory.getClass().getName() );\n\t\t\t\tbuilder = returnedBuilder;\n\t\t\t}\n\t\t}\n\n\t\tif ( activeFactoryNames != null && activeFactoryNames.size() > 1 ) {\n\t\t\tthrow new HibernateException(\n\t\t\t\t\t\"Multiple active MetadataBuilder definitions were discovered : \" +\n\t\t\t\t\t\t\tString.join(\", \", activeFactoryNames)\n\t\t\t);\n\t\t}\n\n\t\treturn builder != null ? builder : defaultBuilder;\n\t}\n\n\t/**\n\t * Shorthand form of calling {@link #getMetadataBuilder()} and using its\n\t * {@link MetadataBuilder#build()} method in cases where the application\n\t * wants to accept the defaults.\n\t *\n\t * @return The built metadata.\n\t */\n\tpublic Metadata buildMetadata() {\n\t\treturn getMetadataBuilder().build();\n\t}","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java#L185-L221","documentation":"MetadataSources.getMetadataBuilder() discovers MetadataBuilderFactory implementations via the JDK ServiceLoader and asks each to provide a builder. Only one factory may be active: when two or more return a builder, Hibernate cannot choose between competing metadata pipelines and throws HibernateException listing the active factory class names. In practice this means the classpath carries competing Hibernate boot providers — usually two hibernate-core versions.","triggerScenarios":"Two jars both providing a MetadataBuilderFactory service (hibernate-core 6.x and 6.y both present via transitive dependencies, a shaded uber-jar, or a bundled WAR plus server-provided Hibernate) where every discovered factory returns a non-null builder.","commonSituations":"Upgrading Hibernate while the old jar lingers in EAR/lib or a server module; dependency mediation leaving two versions; shading merges META-INF/services entries; a custom factory from another framework competing with the built-in one.","solutions":["Run mvn dependency:tree / gradle dependencies, find both paths pulling hibernate-core, and exclude the older one so exactly one version ships.","On application servers, mark hibernate-core provided and use the server's Hibernate instead of bundling your own.","If you register a custom MetadataBuilderFactory, make it return null (decline) unless it must take over."],"exampleFix":"<!-- before: legacy-lib transitively pulls hibernate-core 6.4 alongside your 6.6 -->\n<!-- after -->\n<dependency>\n  <groupId>com.example</groupId>\n  <artifactId>legacy-lib</artifactId>\n  <exclusions>\n    <exclusion>\n      <groupId>org.hibernate</groupId>\n      <artifactId>hibernate-core</artifactId>\n    </exclusion>\n  </exclusions>\n</dependency>","handlingStrategy":"validation","validationCode":"ClassLoader cl = Thread.currentThread().getContextClassLoader();\nEnumeration<URL> locations = cl.getResources(\"org/hibernate/boot/MetadataSources.class\");\nif (Collections.list(locations).size() > 1) {\n    throw new IllegalStateException(\"Multiple hibernate-core jars on classpath: \"\n            + Collections.list(locations));\n}","typeGuard":null,"tryCatchPattern":"Catch org.hibernate.HibernateException around getMetadataBuilder(); when the message starts with 'Multiple active MetadataBuilder definitions', print the factory names and the hibernate-core jar locations, then fix the classpath.","preventionTips":["Run mvn dependency:tree / gradle dependencies after every Hibernate upgrade and keep exactly one hibernate-core.","Use provided scope for container-managed Hibernate.","Beware uber-jar/shading merges of META-INF/services files."],"tags":["hibernate","classpath","dependency-conflict","serviceloader","spi"],"backgroundTag":"duplicate-classpath-dependency","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}