{"record":{"id":"e1038080345bb94f","repo":"hibernate/hibernate-orm","slug":"unable-to-locate-schema-schemaresourcename-vi","errorCode":null,"errorMessage":"Unable to locate schema [${schemaResourceName}] via classpath","messagePattern":"Unable to locate schema \\[(.+?)\\] via classpath","errorType":"exception","errorClass":"XmlInfrastructureException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/LocalSchemaLocator.java","lineNumber":38,"sourceCode":" *\n * @author Steve Ebersole\n */\npublic class LocalSchemaLocator {\n\n\tprivate LocalSchemaLocator() {\n\t\t// Disallow direct instantiation\n\t}\n\n\t/**\n\t * Given the resource name of a schema, locate its URL reference via ClassLoader lookup.\n\t *\n\t * @param schemaResourceName The local resource name to the schema\n\t *\n\t */\n\tpublic static URL resolveLocalSchemaUrl(String schemaResourceName) {\n\t\tfinal URL url = LocalSchemaLocator.class.getClassLoader().getResource( schemaResourceName );\n\t\tif ( url == null ) {\n\t\t\tthrow new XmlInfrastructureException( \"Unable to locate schema [\" + schemaResourceName + \"] via classpath\" );\n\t\t}\n\t\treturn url;\n\t}\n\n\tpublic static Schema resolveLocalSchema(String schemaName){\n\t\treturn resolveLocalSchema( resolveLocalSchemaUrl( schemaName ) );\n\t}\n\n\tpublic static Schema resolveLocalSchema(URL schemaUrl) {\n\t\ttry {\n\t\t\tfinal var schemaStream = schemaUrl.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( schemaUrl.openStream() ) );\n\t\t\t}\n\t\t\tcatch ( Exception e ) {\n\t\t\t\tthrow new XmlInfrastructureException( \"Unable to load schema [\" + schemaUrl.toExternalForm() + \"]\", e );\n\t\t\t}","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/stax/LocalSchemaLocator.java#L20-L56","documentation":"LocalSchemaLocator.resolveLocalSchemaUrl looks up a bundled XSD (e.g. org/hibernate/xsd/...) through hibernate-core's own classloader; a null result throws XmlInfrastructureException 'Unable to locate schema [name] via classpath'. This is an infrastructure defect: the XSD resources that ship inside hibernate-core are not visible where Hibernate is running.","triggerScenarios":"Booting Hibernate in an environment where hibernate-core's resources were stripped or isolated: maven-shade minimizeJar or Gradle minimization dropping .xsd files, ProGuard stripping 'non-class' resources, aggressive classloader isolation (OSGi/PDE, custom module loaders) that cannot see resources from hibernate-core's jar.","commonSituations":"Uber-jar builds that minimize; embedded containers repackaging Hibernate; IDE runtimes with filtered resource output; a broken/partial hibernate-core jar in the local repository.","solutions":["Inspect the packaged artifact: 'jar tf app.jar | grep hibernate/xsd' — if the .xsd entries are gone, fix the build","Add keep/include rules for **/*.xsd (and META-INF) to your shade/minimize configuration","Use an unmodified hibernate-core artifact; if a local repo copy is truncated, delete it and re-resolve","In isolated classloader setups, ensure the loader that loads hibernate-core can also getResource() its own jar entries"],"exampleFix":"<!-- before (shade plugin) -->\n<minimizeJar>true</minimizeJar>\n\n<!-- after -->\n<minimizeJar>true</minimizeJar>\n<filters>\n  <filter>\n    <artifact>org.hibernate.orm:hibernate-core</artifact>\n    <includes>\n      <include>**/*.xsd</include>\n    </includes>\n  </filter>\n</filters>","handlingStrategy":"validation","validationCode":"if (org.hibernate.boot.jaxb.internal.stax.LocalSchemaLocator.class\n        .getClassLoader().getResource(\"org/hibernate/xsd/mapping/mapping-3.1.xsd\") == null) {\n    throw new IllegalStateException(\"hibernate-core XSDs missing from classpath - fix shading/minimization\");\n}","typeGuard":null,"tryCatchPattern":"catch (XmlInfrastructureException e) {\n    throw new IllegalStateException(\"Hibernate infrastructure broken: bundled XSDs not visible - inspect the packaged jar\", e);\n}","preventionTips":["Add '**/*.xsd' keep rules to any shade/minimize/proguard config","Assert in CI that the packaged artifact contains org/hibernate/xsd/**","Never strip resources from hibernate-core when repackaging"],"tags":["classpath","xsd","shading","bootstrap"],"backgroundTag":"classpath-resource-not-found","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}