quarkusio/quarkus · error · IllegalStateException

This method is not available at runtime in Quarkus

Error message

This method is not available at runtime in Quarkus

What it means

FastBootEntityManagerFactoryBuilder.getManagedResources() intentionally refuses to return ManagedResources at runtime. In Quarkus, Hibernate metadata is fully built at augmentation (compile) time, so the runtime EntityManagerFactoryBuilder stub cannot expose the raw resources Hibernate would normally carry. Any code (usually a Hibernate integration or third-party extension) asking for them hits this hard stop.

Source

Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/boot/FastBootEntityManagerFactoryBuilder.java:261

        @Override
        public void sessionFactoryClosed(SessionFactory sessionFactory) {
            SessionFactoryImplementor sfi = ((SessionFactoryImplementor) sessionFactory);
            sfi.getServiceRegistry().destroy();
            ServiceRegistry basicRegistry = sfi.getServiceRegistry().getParentServiceRegistry();
            ((ServiceRegistryImplementor) basicRegistry).destroy();
        }
    }

    private static class JpaEntityNotFoundDelegate implements EntityNotFoundDelegate, Serializable {

        public void handleEntityNotFound(String entityName, Object id) {
            throw new EntityNotFoundException("Unable to find " + entityName + " with id " + id);
        }
    }

    @Override
    public ManagedResources getManagedResources() {
        throw new IllegalStateException("This method is not available at runtime in Quarkus");
    }

    @Override
    public MetadataImplementor metadata() {
        return metadata;
    }

}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Do not call getManagedResources() at runtime; use metadata() instead, which returns the pre-built MetadataImplementor.
  2. If you need ManagedResources, access them at augmentation/build time in a deployment module build step, not at runtime.
  3. Refactor the calling integrator/tool to rely on metadata or service registry data Quarkus does provide.

Example fix

// before
ManagedResources resources = emfBuilder.getManagedResources();
// after
MetadataImplementor metadata = emfBuilder.metadata(); // safe at runtime in Quarkus
Defensive patterns

Strategy: try-catch

Validate before calling

// Before calling, prefer the metadata accessor which is supported at runtime
if (builder instanceof FastBootEntityManagerFactoryBuilder) {
    // do NOT call getManagedResources(); use metadata()
}

Type guard

boolean supportsManagedResources(Object b) {
    return !(b instanceof FastBootEntityManagerFactoryBuilder);
}

Try / catch

try {
    ManagedResources r = builder.getManagedResources();
} catch (IllegalStateException e) {
    // fall back to builder.metadata() for runtime inspection
    MetadataImplementor md = builder.metadata();
}

Prevention

When it happens

Trigger: Calling getManagedResources() on the FastBootEntityManagerFactoryBuilder instance used for a Quarkus-managed persistence unit — typically from custom Hibernate integrators, tools, or tests that inspect ManagedResources at runtime.

Common situations: Porting plain-Hibernate bootstrap code to Quarkus; writing an extension or integrator that reads ManagedResources; running Hibernate tooling (schema export utilities, metadata analyzers) against the runtime bootstrap.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/45fddc1db39cd46b. Report an issue: GitHub.