{"record":{"id":"f4b48ee9bfcf2fa0","repo":"hibernate/hibernate-orm","slug":"could-not-locate-root-element","errorCode":null,"errorMessage":"Could not locate root element","messagePattern":"Could not locate root element","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/JaxbCfgProcessor.java","lineNumber":128,"sourceCode":"\t\tcatch ( JAXBException e ) {\n\t\t\tthrow new ConfigurationException(\n\t\t\t\t\t\"Unable to perform unmarshalling at line number \" + handler.getLineNumber()\n\t\t\t\t\t\t\t+ \" and column \" + handler.getColumnNumber()\n\t\t\t\t\t\t\t+ \" in \" + origin.getType().name() + \" \" + origin.getName()\n\t\t\t\t\t\t\t+ \". Message: \" + handler.getMessage(), e\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate static XMLEvent xmlEvent(XMLEventReader staxEventReader) {\n\t\ttry {\n\t\t\tXMLEvent event = staxEventReader.peek();\n\t\t\twhile ( event != null && !event.isStartElement() ) {\n\t\t\t\tstaxEventReader.nextEvent();\n\t\t\t\tevent = staxEventReader.peek();\n\t\t\t}\n\t\t\tif ( event == null ) {\n\t\t\t\tthrow new HibernateException( \"Could not locate root element\" );\n\t\t\t}\n\t\t\treturn event;\n\t\t}\n\t\tcatch ( Exception e ) {\n\t\t\tthrow new HibernateException( \"Error accessing StAX stream\", e );\n\t\t}\n\t}\n\n\tprivate boolean isNamespaced(StartElement startElement) {\n\t\treturn isNotEmpty( startElement.getName().getNamespaceURI() );\n\t}\n\n\tprivate Schema schema;\n\n\tprivate Schema schema() {\n\t\tif ( schema == null ) {\n\t\t\tschema = resolveLocalSchema( \"org/hibernate/hibernate-configuration-4.0.xsd\" );\n\t\t}","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/JaxbCfgProcessor.java#L110-L146","documentation":"Error \"Could not locate root element\" thrown in hibernate/hibernate-orm.","triggerScenarios":"JAXB cannot parse the XML configuration document.","commonSituations":"Malformed or schema-violating hibernate.cfg.xml content, or a document missing its expected root element.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}