quarkusio/quarkus · error · IllegalStateException
Can only be used in dev or test mode
Error message
Can only be used in dev or test mode
What it means
SchemaManagementIntegrator.recreateDatabases() re-imports/recreates all databases registered with the schema integrator, a Dev Services / dev-mode convenience. It is guarded by LaunchMode.current().isDevOrTest(), so calling it in a production (normal) launch throws IllegalStateException. This protects production data from accidental wholesale recreation.
Source
Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/schema/SchemaManagementIntegrator.java:89
public static void mapDatasource(String datasource, String pu) {
datasourceToPuMap.put(datasource, pu);
}
static String defaultName(SessionFactoryImplementor sf) {
String name = sf.getName();
if (name != null) {
return name;
}
Object persistenceUnitName = sf.getProperties().get(PERSISTENCE_UNIT_NAME);
if (persistenceUnitName != null) {
return persistenceUnitName.toString();
}
return DataSourceUtil.DEFAULT_DATASOURCE_NAME;
}
public static void recreateDatabases() {
if (!LaunchMode.current().isDevOrTest()) {
throw new IllegalStateException("Can only be used in dev or test mode");
}
for (String val : metadataMap.keySet()) {
recreateDatabase(val);
}
}
public static void recreateDatabase(String name) {
if (!LaunchMode.current().isDevOrTest()) {
throw new IllegalStateException("Can only be used in dev or test mode");
}
Holder holder = metadataMap.get(name);
ServiceRegistry serviceRegistry = holder.sessionFactory.getServiceRegistry();
SimpleExecutionOptions executionOptions = new SimpleExecutionOptions(serviceRegistry);
Object schemaGenerationDatabaseAction = executionOptions.getConfigurationValues()
.get("jakarta.persistence.schema-generation.database.action");
if (schemaGenerationDatabaseAction != null && !(schemaGenerationDatabaseAction.toString().equals("none"))) {
//if this is none we assume another framework is doing this (e.g. flyway)View on GitHub (pinned to e1c734241f)
Solutions
- Do not call recreateDatabases in production; guard your code path with LaunchMode checks or remove the call.
- For controlled schema changes in production use Flyway/Liquibase migrations instead of Quarkus dev-mode reset APIs.
- If this is a legitimate dev workflow, run the app with `quarkus dev` or as a test where the launch mode is DEV/TEST.
Example fix
// before
SchemaManagementIntegrator.recreateDatabases();
// after
if (LaunchMode.current().isDevOrTest()) {
SchemaManagementIntegrator.recreateDatabases();
} Defensive patterns
Strategy: validation
Validate before calling
if (!LaunchMode.current().isDevOrTest()) {
throw new IllegalStateException("recreateDatabases is dev/test only");
}
SchemaManagementIntegrator.recreateDatabases(); Try / catch
try {
SchemaManagementIntegrator.recreateDatabases();
} catch (IllegalStateException e) {
log.warn("DB reset skipped: only allowed in dev or test mode", e);
} Prevention
- Never call Quarkus dev-support internal APIs from production code paths
- Gate destructive database operations on LaunchMode checks
- Use Flyway/Liquibase for production schema management
When it happens
Trigger: Programmatically invoking SchemaManagementIntegrator.recreateDatabases() (directly or via resetAllDatabases) while the application runs in a launch mode other than NORMAL — i.e. not quarkus:dev, not tests.
Common situations: Reusing a dev/test support class from production code; an admin/ops endpoint accidentally wired to database-reset logic running in prod; custom tooling calling Quarkus internal APIs at runtime in a packaged jar.
Related errors
- Cannot launch a runtime application with NORMAL launch mode
- Unable to deserialize the dev mode context. Does the Quarkus
- Hot deployment of the application is not supported when upda
- remote-dev can only be used with mutable applications i.e. u
- Failed to create compiler
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/871de2399be33151.
Report an issue: GitHub.