hibernate/hibernate-orm · error · ConfigurationException

Could not locate cfg.xml resource

Error message

Could not locate cfg.xml resource [%s]

What it means

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.

Solutions

  1. Place hibernate.cfg.xml (or the named cfg.xml resource) on the classpath root, e.g. src/main/resources.
  2. Check the resource path passed to configure()/Configuration for typos, including case sensitivity.
  3. Ensure the build tool copies resource files into the output artifact (target/classes or the jar).
Defensive patterns

Strategy: validation

When it happens

Trigger: A hibernate.cfg.xml resource named in the configuration cannot be found.

Common situations: Referencing cfg.xml by a wrong classpath path or file path, or the file not being packaged into the deployment.


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/b30c443a343258a5. Report an issue: GitHub.

Appendix: source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/ConfigLoader.java:56

				public JaxbCfgProcessor initialize() {
					return new JaxbCfgProcessor( bootstrapServiceRegistry.getService( ClassLoaderService.class ) );
				}
			}
	);

	public ConfigLoader(BootstrapServiceRegistry bootstrapServiceRegistry) {
		this.bootstrapServiceRegistry = bootstrapServiceRegistry;
	}

	private InputStream locateStream(String cfgXmlResourceName) {
		return bootstrapServiceRegistry.requireService( ClassLoaderService.class )
				.locateResourceStream( cfgXmlResourceName );
	}

	public LoadedConfig loadConfigXmlResource(String cfgXmlResourceName) {
		final var stream = locateStream( cfgXmlResourceName );
		if ( stream == null ) {
			throw new ConfigurationException( "Could not locate cfg.xml resource [" + cfgXmlResourceName + "]" );
		}

		try {
			return LoadedConfig.consume( jaxbProcessorHolder.getValue()
					.unmarshal( stream, new Origin( RESOURCE, cfgXmlResourceName ) ) );
		}
		finally {
			try {
				stream.close();
			}
			catch (IOException e) {
				BOOT_LOGGER.unableToCloseCfgXmlResourceStream( e );
			}
		}
	}

	public LoadedConfig loadConfigXmlFile(File cfgXmlFile) {
		try ( FileInputStream cfgFileStream = new FileInputStream( cfgXmlFile ) ) {

View on GitHub (pinned to fad1729dce)