{"record":{"id":"459e34314032aeaa","repo":"hibernate/hibernate-orm","slug":"unable-to-perform-unmarshalling-at-line-number","errorCode":null,"errorMessage":"Unable to perform unmarshalling at line number {} and column {}. Message: {}","messagePattern":"Unable to perform unmarshalling at line number (.+?) and column (.+?)\\. Message: (.+?)","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/AbstractBinder.java","lineNumber":165,"sourceCode":"\n\tprotected <X extends T> X jaxb(XMLEventReader reader, Schema xsd, JAXBContext jaxbContext, Origin origin) {\n\t\tfinal ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();\n\n\t\ttry {\n\t\t\tfinal Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();\n\t\t\tif ( isValidationEnabled() ) {\n\t\t\t\tunmarshaller.setSchema( xsd );\n\t\t\t}\n\t\t\telse {\n\t\t\t\tunmarshaller.setSchema( null );\n\t\t\t}\n\t\t\tunmarshaller.setEventHandler( handler );\n\n\t\t\t//noinspection unchecked\n\t\t\treturn (X) unmarshaller.unmarshal( reader );\n\t\t}\n\t\tcatch ( JAXBException e ) {\n\t\t\tthrow new MappingException(\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+ \". Message: \" + handler.getMessage(),\n\t\t\t\t\te,\n\t\t\t\t\torigin\n\t\t\t);\n\t\t}\n\t}\n\n\n}\n","sourceCodeStart":147,"sourceCodeEnd":177,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/AbstractBinder.java#L147-L177","documentation":"JAXB unmarshalling of the mapping document failed; the message embeds the line and column captured by the ValidationEventHandler plus that handler's message. Schema validation is attached to the unmarshaller when enabled, so both raw unmarshal errors and XSD validation failures surface here, wrapped in a MappingException with the Origin.","triggerScenarios":"Binding an hbm.xml/cfg.xml/mapping.xml that violates its XSD: unknown elements or attributes, wrong namespace, text where an integer/date is expected, required attribute missing. Also plain JAXB errors such as unexpected root element names.","commonSituations":"Hand-edited mapping files with typos; files written for a different Hibernate version's schema; copy-pasted snippets from older docs using the old DTD or a stale namespace; attribute values like 'truee' or non-numeric in numeric fields.","solutions":["Go to the reported line:column in the file named by the Origin - the handler message names the offending element/value","Fix the element/attribute per the schema for your Hibernate version (check the bundled XSD or docs)","Verify the root namespace matches the version in use (e.g. current hibernate-mapping/cfg/mapping namespaces)","Run a local schema validation pass to catch remaining errors before boot","If deviating intentionally, validation can be disabled on the binder - but the document must still unmarshal"],"exampleFix":"<!-- before: unknown attribute + bad numeric -->\n<set name=\"tags\" lAZY=\"true\" batch-size=\"ten\">...</set>\n\n<!-- after -->\n<set name=\"tags\" lazy=\"true\" batch-size=\"10\">...</set>","handlingStrategy":"validation","validationCode":"// schema-validate before boot to collect ALL problems with positions\nvar factory = javax.xml.validation.SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);\nvar schema = factory.newSchema(getClass().getResource(\"/org/hibernate/xsd/hibernate-mapping-4.0.xsd\"));\nvar validator = schema.newValidator();\nfinal var problems = new java.util.ArrayList<String>();\nvalidator.setErrorHandler(new org.xml.sax.helpers.DefaultHandler() {\n    public void error(org.xml.sax.SAXParseException e) { problems.add(e.getLine() + \":\" + e.getColumn() + \" \" + e.getMessage()); }\n});\nvalidator.validate(new javax.xml.transform.stream.StreamSource(mappingFile));","typeGuard":null,"tryCatchPattern":"try {\n    binder.bind(stream, origin);\n} catch (MappingException e) {\n    // message carries line/column from the ValidationEventHandler\n    log.error(\"mapping invalid at {}\", e.getMessage(), e.getCause());\n    throw e;\n}","preventionTips":["Validate mapping XML against the Hibernate XSD in CI","Use editor XML schema support while editing mappings","Match document namespaces to the Hibernate version in use"],"tags":["hibernate","jaxb","schema-validation","xml","mapping-file"],"backgroundTag":"jaxb-schema-validation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}