hibernate/hibernate-orm · critical · HibernateException
Multiple active MetadataBuilder definitions were discovered
Error message
Multiple active MetadataBuilder definitions were discovered : <activeFactoryNames>
What it means
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.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/MetadataSources.java:203
.loadJavaServices( MetadataBuilderFactory.class );
MetadataBuilder builder = null;
List<String> activeFactoryNames = null;
for ( MetadataBuilderFactory discoveredBuilderFactory : discoveredBuilderFactories) {
final MetadataBuilder returnedBuilder =
discoveredBuilderFactory.getMetadataBuilder( this, defaultBuilder );
if ( returnedBuilder != null ) {
if ( activeFactoryNames == null ) {
activeFactoryNames = new ArrayList<>();
}
activeFactoryNames.add( discoveredBuilderFactory.getClass().getName() );
builder = returnedBuilder;
}
}
if ( activeFactoryNames != null && activeFactoryNames.size() > 1 ) {
throw new HibernateException(
"Multiple active MetadataBuilder definitions were discovered : " +
String.join(", ", activeFactoryNames)
);
}
return builder != null ? builder : defaultBuilder;
}
/**
* Shorthand form of calling {@link #getMetadataBuilder()} and using its
* {@link MetadataBuilder#build()} method in cases where the application
* wants to accept the defaults.
*
* @return The built metadata.
*/
public Metadata buildMetadata() {
return getMetadataBuilder().build();
}View on GitHub (pinned to fad1729dce)
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.
Example fix
<!-- before: legacy-lib transitively pulls hibernate-core 6.4 alongside your 6.6 -->
<!-- after -->
<dependency>
<groupId>com.example</groupId>
<artifactId>legacy-lib</artifactId>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</exclusion>
</exclusions>
</dependency> Defensive patterns
Strategy: validation
Validate before calling
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Enumeration<URL> locations = cl.getResources("org/hibernate/boot/MetadataSources.class");
if (Collections.list(locations).size() > 1) {
throw new IllegalStateException("Multiple hibernate-core jars on classpath: "
+ Collections.list(locations));
} Try / catch
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.
Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Multiple SchemaManagementTool service registrations found vi
- Implementation class [{}] does not implement strategy interf
- Multiple StatisticsFactory service registrations found via S
- Unable to determine JAR Url from <url>. Cause: <cause>
- Could not resolve jar-file: <jarFileReference>
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/e6b583b9109f48c3.
Report an issue: GitHub.