hibernate/hibernate-orm · error · HibernateException
Could not locate root element
Error message
Could not locate root element
What it means
Error "Could not locate root element" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/JaxbCfgProcessor.java:128
catch ( JAXBException e ) {
throw new ConfigurationException(
"Unable to perform unmarshalling at line number " + handler.getLineNumber()
+ " and column " + handler.getColumnNumber()
+ " in " + origin.getType().name() + " " + origin.getName()
+ ". Message: " + handler.getMessage(), e
);
}
}
private static XMLEvent xmlEvent(XMLEventReader staxEventReader) {
try {
XMLEvent event = staxEventReader.peek();
while ( event != null && !event.isStartElement() ) {
staxEventReader.nextEvent();
event = staxEventReader.peek();
}
if ( event == null ) {
throw new HibernateException( "Could not locate root element" );
}
return event;
}
catch ( Exception e ) {
throw new HibernateException( "Error accessing StAX stream", e );
}
}
private boolean isNamespaced(StartElement startElement) {
return isNotEmpty( startElement.getName().getNamespaceURI() );
}
private Schema schema;
private Schema schema() {
if ( schema == null ) {
schema = resolveLocalSchema( "org/hibernate/hibernate-configuration-4.0.xsd" );
}View on GitHub (pinned to fad1729dce)
Solutions
- Ensure the cfg.xml file is not empty and contains the expected root element (hibernate-configuration).
- Check that the XML document is well-formed and the parser is positioned on the root element.
- Verify the file encoding does not prepend a BOM or junk that breaks parsing.
When it happens
Trigger: JAXB cannot parse the XML configuration document.
Common situations: Malformed or schema-violating hibernate.cfg.xml content, or a document missing its expected root element.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/f4b48ee9bfcf2fa0.
Report an issue: GitHub.