{"record":{"id":"b30c443a343258a5","repo":"hibernate/hibernate-orm","slug":"could-not-locate-cfg-xml-resource-s","errorCode":null,"errorMessage":"Could not locate cfg.xml resource [%s]","messagePattern":"Could not locate cfg\\.xml resource \\[(.+?)\\]","errorType":"exception","errorClass":"ConfigurationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/ConfigLoader.java","lineNumber":56,"sourceCode":"\t\t\t\tpublic JaxbCfgProcessor initialize() {\n\t\t\t\t\treturn new JaxbCfgProcessor( bootstrapServiceRegistry.getService( ClassLoaderService.class ) );\n\t\t\t\t}\n\t\t\t}\n\t);\n\n\tpublic ConfigLoader(BootstrapServiceRegistry bootstrapServiceRegistry) {\n\t\tthis.bootstrapServiceRegistry = bootstrapServiceRegistry;\n\t}\n\n\tprivate InputStream locateStream(String cfgXmlResourceName) {\n\t\treturn bootstrapServiceRegistry.requireService( ClassLoaderService.class )\n\t\t\t\t.locateResourceStream( cfgXmlResourceName );\n\t}\n\n\tpublic LoadedConfig loadConfigXmlResource(String cfgXmlResourceName) {\n\t\tfinal var stream = locateStream( cfgXmlResourceName );\n\t\tif ( stream == null ) {\n\t\t\tthrow new ConfigurationException( \"Could not locate cfg.xml resource [\" + cfgXmlResourceName + \"]\" );\n\t\t}\n\n\t\ttry {\n\t\t\treturn LoadedConfig.consume( jaxbProcessorHolder.getValue()\n\t\t\t\t\t.unmarshal( stream, new Origin( RESOURCE, cfgXmlResourceName ) ) );\n\t\t}\n\t\tfinally {\n\t\t\ttry {\n\t\t\t\tstream.close();\n\t\t\t}\n\t\t\tcatch (IOException e) {\n\t\t\t\tBOOT_LOGGER.unableToCloseCfgXmlResourceStream( e );\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic LoadedConfig loadConfigXmlFile(File cfgXmlFile) {\n\t\ttry ( FileInputStream cfgFileStream = new FileInputStream( cfgXmlFile ) ) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/ConfigLoader.java#L38-L74","documentation":"Raised in loadConfigXmlResource when ClassLoaderService.locateResourceStream returns null for the requested cfg.xml resource name: no classloader in the strategy chain can see the resource. The resource path given to configure() is misspelled or not on the classpath.","triggerScenarios":"A hibernate.cfg.xml resource named in the configuration cannot be found.","commonSituations":"Referencing cfg.xml by a wrong classpath path or file path, or the file not being packaged into the deployment.","solutions":["Place hibernate.cfg.xml (or the named cfg.xml resource) on the classpath root, e.g. src/main/resources.","Check the resource path passed to configure()/Configuration for typos, including case sensitivity.","Ensure the build tool copies resource files into the output artifact (target/classes or the jar)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}