hibernate/hibernate-orm · error · UnsupportedOperationException
#buildNamedQueryRepository should not be called on InFlightM
Error message
#buildNamedQueryRepository should not be called on InFlightMetadataCollector
What it means
InFlightMetadataCollectorImpl is the write-time view of metadata during bootstrap; #buildNamedQueryRepository is a terminal operation that Hibernate itself calls on the completed MetadataImplementor at the end of bootstrap. Calling it on the in-flight collector throws UnsupportedOperationException by design, to flag API misuse.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java:258
}
@Override
public SqmFunctionRegistry getFunctionRegistry() {
return bootstrapContext.getFunctionRegistry();
}
@Override
public Database getDatabase() {
// important to delay this instantiation until as late as possible.
if ( database == null ) {
database = new Database( options );
}
return database;
}
@Override
public NamedObjectRepository buildNamedQueryRepository() {
throw new UnsupportedOperationException( "#buildNamedQueryRepository should not be called on InFlightMetadataCollector" );
}
@Override
public List<PersistenceUnitCallbackDefinition> getPersistenceUnitLifecycleCallbackDefinitions() {
return PersistenceUnitCallbackDefinition.from(
globalRegistrations.getPersistenceUnitLifecycleEventHandlers() );
}
@Override
public Map<String, SqmFunctionDescriptor> getSqlFunctionMap() {
return sqlFunctionMap;
}
@Override
public Set<String> getContributors() {
throw new UnsupportedOperationException();
}
View on GitHub (pinned to fad1729dce)
Solutions
- Move the call to after bootstrap, on the Metadata instance returned by MetadataBuilder#build()
- If you must hook mid-bootstrap, use InFlightMetadataCollectorDelegate and only touch in-flight state, never terminal operations
- Check the stack trace for the integration making the call and upgrade it to a Hibernate-compatible version
Example fix
// before: terminal call during bootstrap
public void contribute(InFlightMetadataCollector metadata) {
metadata.buildNamedQueryRepository(); // UnsupportedOperationException
}
// after: operate on completed metadata
Metadata completed = metadataBuilder.build();
NamedObjectRepository repo = ((MetadataImplementor) completed).buildNamedQueryRepository(); Defensive patterns
Strategy: type-guard
Type guard
if (metadata instanceof InFlightMetadataCollector) {
return; // bootstrap still in progress: defer all terminal operations
}
NamedObjectRepository repo = ((MetadataImplementor) metadata).buildNamedQueryRepository(); Try / catch
try {
metadata.buildNamedQueryRepository();
}
catch (UnsupportedOperationException e) {
// wrong phase: re-run the logic on the Metadata returned by MetadataBuilder#build()
} Prevention
- Only call terminal Metadata operations on the instance returned by MetadataBuilder#build()
- Write integrations against InFlightMetadataCollectorDelegate, which mirrors the in-flight API
When it happens
Trigger: Code that receives metadata during bootstrap - custom Integrators, MetadataSourceProcessors, or anything holding the InFlightMetadataCollectorImpl passed through those SPIs - and invokes buildNamedQueryRepository() on it before MetadataBuilder#build() has finished.
Common situations: Custom integrations trying to inspect named queries mid-bootstrap; frameworks or tutorials written against older/less-segmented Hibernate metadata APIs; upgrades where a previously tolerated call now fails fast.
Related errors
- You should not be building a SessionFactory from an in-fligh
- Bootstrap registry should only contain provided services
- AbstractDelegatingMetadataBuildingOptions delegate did not i
- SessionFactory UUID cannot be null
- The {storageEngine} storage engine is not supported
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/1c6f71012b581496.
Report an issue: GitHub.