hibernate/hibernate-orm · error · ConfigurationException

Unable to build orm.xml JAXBContext

Error message

Unable to build orm.xml JAXBContext

What it means

A ConfigurationException thrown when JAXBContext.newInstance(JaxbEntityMappingsImpl.class) fails while Hibernate prepares to bind orm.xml (JPA mapping) documents. As with the hbm variant, the wrapped JAXBException means the JAXB runtime could not be created — a classpath/JAXB-provider problem, independent of your mapping content.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/MappingBinder.java:211

		if ( hbmJaxbContext == null ) {
			try {
				hbmJaxbContext = JAXBContext.newInstance( JaxbHbmHibernateMapping.class );
			}
			catch (JAXBException e) {
				throw new ConfigurationException( "Unable to build hbm.xml JAXBContext", e );
			}
		}
		return hbmJaxbContext;
	}

	@Internal
	public JAXBContext mappingJaxbContext() {
		if ( entityMappingsJaxbContext == null ) {
			try {
				entityMappingsJaxbContext = JAXBContext.newInstance( JaxbEntityMappingsImpl.class );
			}
			catch (JAXBException e) {
				throw new ConfigurationException( "Unable to build orm.xml JAXBContext", e );
			}
		}
		return entityMappingsJaxbContext;
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add jakarta.xml.bind-api + org.glassfish.jaxb:jaxb-runtime aligned with your Hibernate version
  2. Audit the dependency tree and exclude javax.xml.bind:javax.xml.bind-api, com.sun.xml.bind, or MOXy artifacts that hijack the provider
  3. If shading, preserve META-INF/services entries and the whole org.glassfish.jaxb package

Example fix

// quick probe to run before bootstrap
Class.forName("jakarta.xml.bind.JAXBContext");
JAXBContext.newInstance(org.hibernate.boot.jaxb.internal.MappingBinder.class.getModule(), Object.class); // smoke test
Defensive patterns

Strategy: validation

Validate before calling

try {
    jakarta.xml.bind.JAXBContext.newInstance(org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappingsImpl.class);
} catch (jakarta.xml.bind.JAXBException e) {
    throw new IllegalStateException("JAXB runtime unusable - fix classpath before bootstrap", e);
}

Try / catch

catch (ConfigurationException e) {
    if (e.getCause() instanceof jakarta.xml.bind.JAXBException) {
        throw new IllegalStateException("JAXB runtime conflict while building orm.xml context - audit dependency:tree", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Any bootstrap that processes an orm.xml: missing jakarta.xml.bind runtime on JDK 11+, mixed javax/jakarta JAXB artifacts, a JAXB provider (e.g. EclipseLink MOXy) registered via META-INF/services that cannot handle Hibernate's generated classes, or shading that strips provider metadata.

Common situations: Migrating an app to Jakarta EE 9+ namespaces while an old javax JAXB jar remains; deploying into containers that provide their own JAXB; uber-jar builds dropping META-INF/services/jakarta.xml.bind.JAXBContext.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/26ba2311f2051a93. Report an issue: GitHub.