{"record":{"id":"6feeb5a0fd17913d","repo":"hibernate/hibernate-orm","slug":"unable-to-load-schema","errorCode":null,"errorMessage":"Unable to load schema [{}]","messagePattern":"Unable to load schema \\[(.+?)\\]","errorType":"exception","errorClass":"XsdException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/xsd/LocalXsdResolver.java","lineNumber":87,"sourceCode":"\t\t}\n\n\t\treturn null;\n\t}\n\n\n\tpublic static Schema resolveLocalXsdSchema(String schemaResourceName) {\n\t\tfinal URL url = resolveLocalXsdUrl( schemaResourceName );\n\t\tif ( url == null ) {\n\t\t\tthrow new XsdException( \"Unable to locate schema [\" + schemaResourceName + \"] via classpath\", schemaResourceName );\n\t\t}\n\t\ttry {\n\t\t\tfinal var schemaStream = url.openStream();\n\t\t\ttry {\n\t\t\t\treturn SchemaFactory.newInstance( W3C_XML_SCHEMA_NS_URI )\n\t\t\t\t\t\t.newSchema( new StreamSource( url.openStream() ) );\n\t\t\t}\n\t\t\tcatch ( SAXException | IOException e ) {\n\t\t\t\tthrow new XsdException( \"Unable to load schema [\" + schemaResourceName + \"]\", e, schemaResourceName );\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\ttry {\n\t\t\t\t\tschemaStream.close();\n\t\t\t\t}\n\t\t\t\tcatch ( IOException e ) {\n\t\t\t\t\tJAXB_LOGGER.problemClosingSchemaStream( e.toString() );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tcatch ( IOException e ) {\n\t\t\tthrow new XsdException( \"Stream error handling schema url [\" + url.toExternalForm() + \"]\", schemaResourceName );\n\t\t}\n\t}\n\n\tpublic static XsdDescriptor buildXsdDescriptor(String resourceName, String version, String namespaceUri) {\n\t\treturn new XsdDescriptor( resourceName, resolveLocalXsdSchema( resourceName ), version, namespaceUri );\n\t}","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/xsd/LocalXsdResolver.java#L69-L105","documentation":"The schema resource was located, but SchemaFactory.newSchema() threw SAXException, or opening its stream threw IOException. That means the bytes behind the URL are not a parseable W3C XML Schema - the resource exists but is damaged, truncated, or not actually XSD content. Hibernate wraps the failure in XsdException with the resource name and original cause.","triggerScenarios":"resolveLocalXsdSchema() on a schema whose stream yields invalid/corrupted XML: jar damaged in transit or by re-packaging, a filtering/templating build step that mangled the XSD text, or a same-named resource earlier on the classpath shadowing Hibernate's bundled one.","commonSituations":"Maven resource filtering enabled for the shaded jar (placeholder substitution corrupting schema files); a broken mirror serving a truncated hibernate-core jar; a project shipping its own org/hibernate/xsd/... file that gets resolved first; disk/full-cache corruption in an artifact repository.","solutions":["Open the URL from the message and try loading it with a plain XML parser - confirm the content is a valid XSD.","Check for classpath shadowing: another artifact providing the same resource path earlier in resolution order; remove or fix it.","Disable resource filtering/minification for *.xsd files in the build and rebuild the jar.","Re-fetch hibernate-core from a trusted repository after verifying its checksum, then clean the local cache entry."],"exampleFix":"# before\n# maven-resources filtering applied to all files, corrupting hibernate's xsd\n<resource><directory>...</directory><filtering>true</filtering></resource>\n\n# after\n<resource><directory>...</directory><filtering>true</filtering><excludes><exclude>**/*.xsd</exclude></excludes></resource>","handlingStrategy":"try-catch","validationCode":"static boolean parsesAsSchema(String resource) {\n    URL url = Thread.currentThread().getContextClassLoader().getResource( resource );\n    if ( url == null ) return false;\n    try ( var in = url.openStream() ) {\n        SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI ).newSchema( new StreamSource( in ) );\n        return true;\n    }\n    catch ( Exception e ) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try { return LocalXsdResolver.resolveLocalXsdSchema( name ); }\ncatch ( XsdException e ) {\n    if ( e.getMessage().startsWith( \"Unable to load schema\" ) && e.getCause() instanceof SAXException sax ) {\n        // resource present but corrupt -> verify jar checksum, look for shadowing resource\n        reportCorruptedArtifact( name, sax );\n    }\n    throw e;\n}","preventionTips":["Keep resource filtering and minification away from *.xsd files in every build.","Verify artifact checksums when fetching hibernate-core from mirrors/proxies.","Search for duplicate same-path resources on the classpath when this appears: first match wins and may be broken."],"tags":["hibernate","xsd","sax","corrupted-resource","schema"],"backgroundTag":"xsd-schema-parse-failure","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}