hibernate/hibernate-orm · error · HibernateException

Unable to create StAX reader

Error message

Unable to create StAX reader

What it means

Error "Unable to create StAX reader" thrown in hibernate/hibernate-orm.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/JaxbCfgProcessor.java:74

		this.xmlResourceResolver = new LocalXmlResourceResolver( classLoaderService );
	}

	public JaxbCfgHibernateConfiguration unmarshal(InputStream stream, Origin origin) {
		try {
			final var staxReader = staxFactory().createXMLEventReader( stream );
			try {
				return unmarshal( staxReader, origin );
			}
			finally {
				try {
					staxReader.close();
				}
				catch ( Exception ignore ) {
				}
			}
		}
		catch ( XMLStreamException e ) {
			throw new HibernateException( "Unable to create StAX reader", e );
		}
	}

	private XMLInputFactory staxFactory;

	private XMLInputFactory staxFactory() {
		if ( staxFactory == null ) {
			staxFactory = buildStaxFactory();
		}
		return staxFactory;
	}

	private XMLInputFactory buildStaxFactory() {
		final var staxFactory = XMLInputFactory.newInstance();
		staxFactory.setXMLResolver( xmlResourceResolver );
		return staxFactory;
	}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Ensure a StAX implementation is available on the classpath (JREs normally bundle one; on trimmed runtimes add e.g. woodstox).
  2. Check for XML parser conflicts caused by shaded or old xerces/xalan jars; remove duplicates.
  3. Inspect the causal exception for I/O problems reading the cfg.xml input.

When it happens

Trigger: The JDK StAX parser fails while reading a Hibernate XML configuration file.

Common situations: Malformed XML in hibernate.cfg.xml, or XML parser/dependency conflicts on the classpath.


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