{"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":"Error \"Could not locate cfg.xml resource [%s]\" thrown in hibernate/hibernate-orm.","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":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"}