hibernate/hibernate-orm · error · ConfigurationException

Unable to build configuration.xml JAXBContext

Error message

Unable to build configuration.xml JAXBContext

What it means

ConfigurationBinder could not create the JAXBContext used to read configuration.xml/persistence.xml: JAXBContext.newInstance(JaxbPersistenceImpl.class) threw JAXBException, wrapped in ConfigurationException. On modern JDKs the dominant cause is a missing JAXB runtime - java.xml.bind was removed from the JDK in Java 11 - or a broken/conflicting JAXB implementation on the classpath.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/ConfigurationBinder.java:62

		final XMLEventReader reader = new ConfigurationEventReader( staxEventReader, xmlEventFactory );
		final JaxbPersistenceImpl bindingRoot = jaxb(
				reader,
				ConfigXsdSupport.latestDescriptor().getSchema(),
				jaxbContext(),
				origin
		);
		//noinspection unchecked
		return new Binding<>( (X) bindingRoot, origin );
	}

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

View on GitHub (pinned to fad1729dce)

Solutions

  1. Add the JAXB API and a runtime matching your Hibernate version's namespace (jakarta.xml.bind-api + org.glassfish.jaxb:jaxb-runtime for jakarta-flavored Hibernate 6.2+; javax versions for older lines)
  2. Verify only one jaxb runtime resolves: mvn dependency:tree | grep -i jaxb (or gradle equivalent)
  3. Confirm the fix with a trivial Class.forName check on the JAXBContext class before bootstrapping
  4. If you do not use configuration.xml/persistence.xml at all, build Configuration/Metadata programmatically to bypass the XML binder

Example fix

<!-- before: JDK 11+, no JAXB on classpath -> ConfigurationException -->
<dependencies>
    <dependency>org.hibernate.orm:hibernate-core:6.x</dependency>
</dependencies>

<!-- after -->
<dependencies>
    <dependency>org.hibernate.orm:hibernate-core:6.x</dependency>
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
    </dependency>
</dependencies>
Defensive patterns

Strategy: validation

Validate before calling

// verify a JAXB runtime is present before bootstrapping XML config
try {
    Class.forName("jakarta.xml.bind.JAXBContext");   // Hibernate 6.2+
    // Class.forName("javax.xml.bind.JAXBContext");  // older lines
} catch (ClassNotFoundException e) {
    throw new IllegalStateException("No JAXB runtime on JDK 11+: add jakarta.xml.bind-api + jaxb-runtime", e);
}

Try / catch

try {
    configurationBinder.jaxbContext();
} catch (ConfigurationException e) {
    // almost always a missing/conflicting JAXB runtime: fix the classpath, not the code
    throw new IllegalStateException("Add a JAXB runtime to the application classpath", e);
}

Prevention

When it happens

Trigger: Running Hibernate's native XML configuration bootstrapping on JDK 11+ without jakarta/javax XML bind API and a runtime (e.g. glassfish jaxb-runtime) on the classpath; or with mismatched jaxb-api/jaxb-impl versions fighting each other.

Common situations: Apps upgraded from JDK 8 to 11/17 without adding explicit JAXB dependencies; slimmed runtimes (jlink, some app servers) stripping JAXB; multiple jaxb-runtime versions via transitive deps.

Related errors


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