quarkusio/quarkus · error · IllegalStateException
Persistence providers are not available during the static in
Error message
Persistence providers are not available during the static init phase.
What it means
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).
Source
Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/StaticInitHibernatePersistenceProviderResolver.java:15
package io.quarkus.hibernate.orm.runtime;
import java.util.List;
import jakarta.persistence.spi.PersistenceProvider;
import jakarta.persistence.spi.PersistenceProviderResolver;
/**
* During the static init phase, we don't access the PersistenceProviderResolver.
*/
final class StaticInitHibernatePersistenceProviderResolver implements PersistenceProviderResolver {
@Override
public List<PersistenceProvider> getPersistenceProviders() {
throw new IllegalStateException("Persistence providers are not available during the static init phase.");
}
@Override
public void clearCachedProviders() {
throw new IllegalStateException("Persistence providers are not available during the static init phase.");
}
}
View on GitHub (pinned to e1c734241f)
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.
Example fix
// before
public class Cache {
static final EntityManagerFactory EMF = Persistence.createEntityManagerFactory("pu");
}
// after
@ApplicationScoped
public class Cache {
@Inject EntityManagerFactory emf; // runtime-initialized via Quarkus
} Defensive patterns
Strategy: validation
Validate before calling
// Native build args: defer JPA-touching classes to runtime init quarkus.native.additional-build-args=--initialize-at-run-time=com.acme.Cache,com.acme.JpaBootstrap
Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot retrieve a connection to the database during Quarkus'
- Command line arguments not available during static init
- This PersistenceProvider does not support createEntityManage
- Unable to find an EntityManagerFactory for persistence unit
- Persistence unit is closed
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/4f095a0be37704ca.
Report an issue: GitHub.