hibernate/hibernate-orm · error · IllegalStateException

No child ServiceRegistry registrations found

Error message

No child ServiceRegistry registrations found

What it means

When a child registry closes, it calls deRegisterChild on its parent; if the parent's childRegistries set was never initialized (registerChild was never called with any child), the parent throws IllegalStateException("No child ServiceRegistry registrations found"). It indicates broken parent/child wiring: this child was never actually registered with this parent, or deregistration is happening out of order.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java:419

				SERVICE_LOGGER.unableToStopService( binding.getServiceRole().getName(), e );
			}
		}
	}

	@Override
	public synchronized void registerChild(@Nonnull ServiceRegistryImplementor child) {
		if ( childRegistries == null ) {
			childRegistries = new HashSet<>();
		}
		if ( !childRegistries.add( child ) ) {
			SERVICE_LOGGER.warnf( "Child ServiceRegistry [%s] was already registered; this will end badly later", child );
		}
	}

	@Override
	public synchronized void deRegisterChild(@Nonnull ServiceRegistryImplementor child) {
		if ( childRegistries == null ) {
			throw new IllegalStateException( "No child ServiceRegistry registrations found" );
		}
		childRegistries.remove( child );
		if ( childRegistries.isEmpty() ) {
			if ( autoCloseRegistry ) {
				SERVICE_LOGGER.destroyingServiceRegistry();
				destroy();
			}
			else {
				SERVICE_LOGGER.skippingDestroyingServiceRegistry();
			}
		}
	}

	/**
	 * Not intended for general use. We need the ability to stop and "reactivate" a registry to allow
	 * experimentation with technologies such as GraalVM, Quarkus and Cri-O.
	 */
	public synchronized void resetParent(@Nullable BootstrapServiceRegistry newParent) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Use one shared BootstrapServiceRegistry for all StandardServiceRegistries/SessionFactories so parent-child links stay consistent
  2. Close each SessionFactory and its registry exactly once, child before parent
  3. Upgrade to the latest 6.x — several shutdown/double-close ordering fixes have landed
  4. If you build registries manually, always construct children through APIs that call registerChild (the constructors do)

Example fix

// before
BootstrapServiceRegistry b1 = new BootstrapServiceRegistryBuilder().build();
StandardServiceRegistry r1 = new StandardServiceRegistryBuilder(b1).build();
// later, accidentally: r1 built from b1, but something calls b2 (another instance).deRegisterChild(...)

// after
// one shared bootstrap for the whole application
static final BootstrapServiceRegistry BOOTSTRAP = new BootstrapServiceRegistryBuilder().build();
StandardServiceRegistry registry = new StandardServiceRegistryBuilder(BOOTSTRAP).build();
SessionFactory sf = new MetadataBuilderImpl(registry).build().buildSessionFactory();
// close once, in reverse order: sf.close() -> registry (auto-closed) -> BOOTSTRAP last
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure child was actually parented before closing it
// (construct children only via StandardServiceRegistryBuilder(bootstrap))
if (registry instanceof StandardServiceRegistryImpl impl) {
    impl.close(); // child deregisters itself from its real parent
}

Try / catch

try {
    bootstrapRegistry.close();
}
catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().contains("No child ServiceRegistry")) {
        LOG.debug("children already deregistered/closed; nothing to do", e);
    }
    else throw e;
}

Prevention

When it happens

Trigger: Building a SessionFactory against one BootstrapServiceRegistry but closing against a different instance; manual registry plumbing that skips the constructor's parent.registerChild; double-close paths where the first close already tore down the parent's child set.

Common situations: Application-managed factories created on separate bootstraps (e.g., per-tenant registries built inconsistently); test cleanup closing registries in the wrong order; older Hibernate versions with double-close bugs in SessionFactoryImpl shutdown.

Related errors


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