{"record":{"id":"4f095a0be37704ca","repo":"quarkusio/quarkus","slug":"persistence-providers-are-not-available-during-the","errorCode":null,"errorMessage":"Persistence providers are not available during the static init phase.","messagePattern":"Persistence providers are not available during the static init phase\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/StaticInitHibernatePersistenceProviderResolver.java","lineNumber":15,"sourceCode":"package io.quarkus.hibernate.orm.runtime;\n\nimport java.util.List;\n\nimport jakarta.persistence.spi.PersistenceProvider;\nimport jakarta.persistence.spi.PersistenceProviderResolver;\n\n/**\n * During the static init phase, we don't access the PersistenceProviderResolver.\n */\nfinal class StaticInitHibernatePersistenceProviderResolver implements PersistenceProviderResolver {\n\n    @Override\n    public List<PersistenceProvider> getPersistenceProviders() {\n        throw new IllegalStateException(\"Persistence providers are not available during the static init phase.\");\n    }\n\n    @Override\n    public void clearCachedProviders() {\n        throw new IllegalStateException(\"Persistence providers are not available during the static init phase.\");\n    }\n\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/StaticInitHibernatePersistenceProviderResolver.java#L1-L24","documentation":"During native-image static init, Hibernate ORM installs this placeholder PersistenceProviderResolver that intentionally fails: JPA provider discovery cannot run in that phase because the real providers are created during record/init time. The throw is a guard against code paths that try to bootstrap persistence too early (e.g. Persistence.createEntityManagerFactory during static initialization of a GraalVM native build).","triggerScenarios":"Calling Persistence.createEntityManagerFactory / PersistenceProviderResolver.getPersistenceProviders during static init of a native image; running entity code in a static initializer or a class initialized at build time; library code touching the JPA bootstrap during image generation.","commonSituations":"Native builds failing because a third-party library or test harness statically initializes Hibernate; custom code in static blocks creating EntityManagers; ArC build-time-initialized beans touching JPA.","solutions":["Ensure JPA access happens only at runtime init: keep PU bootstrap in Quarkus-managed beans (or mark classes @InitializeOnce / runtime-init via quarkus.native.additional-build-args --initialize-at-run-time=...).","Remove Persistence.createEntityManagerFactory calls from static initializers; inject EntityManager/EntityManagerFactory via CDI instead.","Identify the class initialized at build time from the native build log and defer its initialization.","Use QuarkusTest with JVM mode to separate runtime behavior from native static-init issues."],"exampleFix":"// before\npublic class Cache {\n    static final EntityManagerFactory EMF = Persistence.createEntityManagerFactory(\"pu\");\n}\n// after\n@ApplicationScoped\npublic class Cache {\n    @Inject EntityManagerFactory emf; // runtime-initialized via Quarkus\n}","handlingStrategy":"validation","validationCode":"// Native build args: defer JPA-touching classes to runtime init\nquarkus.native.additional-build-args=--initialize-at-run-time=com.acme.Cache,com.acme.JpaBootstrap","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call Persistence.createEntityManagerFactory in static initializers","Inject EntityManager/EntityManagerFactory via CDI","Audit --initialize-at-build-time entries for anything touching JPA","Reproduce in JVM mode with -Dquarkus.native.native-image-xmx to spot early-init classes"],"tags":["native-image","static-init","jpa","hibernate-orm","quarkus"],"backgroundTag":"static-init-not-supported","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}