hibernate/hibernate-orm · error · UnsupportedOperationException
MySQL does not support dropping creating/dropping schemas in
Error message
MySQL does not support dropping creating/dropping schemas in the JDBC sense
What it means
MySQL maps JDBC catalogs to databases and has no separate JDBC-style schema object, so MySQLLegacyDialect.canCreateSchema() returns false and getCreateSchemaCommand()/getDropSchemaCommand() throw UnsupportedOperationException instead of returning DDL. Hibernate raises this when its schema-management tooling (hibernate.hbm2ddl.auto, SchemaExport/SchemaUpdate) or schema-based multi-tenancy asks the dialect to emit CREATE SCHEMA for MySQL, because no valid MySQL statement exists for that request; database lifecycle goes through the catalog commands (create/drop database) instead.
Source
Thrown at hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/MySQLLegacyDialect.java:1022
@Override
public String[] getCreateCatalogCommand(String catalogName) {
return new String[] { "create database " + catalogName };
}
@Override
public String[] getDropCatalogCommand(String catalogName) {
return new String[] { "drop database " + catalogName };
}
@Override
public boolean canCreateSchema() {
return false;
}
@Override
public String[] getCreateSchemaCommand(String schemaName) {
throw new UnsupportedOperationException( "MySQL does not support dropping creating/dropping schemas in the JDBC sense" );
}
@Override
public String[] getDropSchemaCommand(String schemaName) {
throw new UnsupportedOperationException( "MySQL does not support dropping creating/dropping schemas in the JDBC sense" );
}
@Override
public boolean supportsIfExistsBeforeTableName() {
return true;
}
@Override
public String getSelectGUIDString() {
return "select uuid()";
}
@OverrideView on GitHub (pinned to fad1729dce)
Solutions
- Use the catalog side on MySQL: set hibernate.default_catalog and @Table(catalog=...) so Hibernate maps to create/drop database instead of schema DDL
- Create or drop the database out-of-band (Flyway/Liquibase or provisioning scripts) before Hibernate starts
- For multi-tenancy on MySQL, switch from schema-per-tenant to database/catalog-per-tenant since canCreateSchema() is false
- Guard programmatic schema tools with dialect.canCreateSchema() before invoking any schema creation path
Example fix
// before @Entity @Table(name = "orders", schema = "sales") // hibernate.default_schema=sales -> getCreateSchemaCommand() throws on MySQL // after @Entity @Table(name = "orders", catalog = "sales") // hibernate.default_catalog=sales -> dialect emits 'create/drop database'
Defensive patterns
Strategy: validation
Validate before calling
Dialect dialect = sessionFactory.getJdbcServices().getDialect();
if ( !dialect.canCreateSchema() ) {
// MySQL: provision the database yourself instead of asking Hibernate for schema DDL
try ( Statement st = connection.createStatement() ) {
st.execute( "create database if not exists sales" );
}
} Try / catch
try {
new SchemaExport( metadata ).createOnly( EnumSet.of( TargetType.DATABASE ), serviceRegistry );
}
catch ( UnsupportedOperationException e ) {
// MySQL rejects JDBC-style schema DDL: create/drop the database out-of-band, then retry without schema DDL
} Prevention
- Never set hibernate.default_schema with MySQLLegacyDialect; use hibernate.default_catalog
- Check Dialect.canCreateSchema() before any programmatic schema creation or drop
- Keep database lifecycle DDL in Flyway/Liquibase rather than hbm2ddl on MySQL
When it happens
Trigger: hibernate.hbm2ddl.auto=create or create-drop combined with hibernate.default_schema or @Table(schema=...) mappings on MySQL; programmatic SchemaExport.create()/drop() runs that need schema DDL; MultiTenancyStrategy.SCHEMA connection providers against MySQL.
Common situations: Porting an application from PostgreSQL (which has real schemas) to MySQL while keeping schema attributes in entity mappings; teams assuming 'schema' and 'database' are interchangeable Hibernate settings; tenant provisioning code written against a schema-per-tenant design.
Related errors
- No create schema syntax supported by " + getClass().getName(
- No drop schema syntax supported by " + getClass().getName()
- The {storageEngine} storage engine is not supported
- SingleStore does not support dropping creating/dropping sche
- all @TenantId fields must have the same type: <parameterType
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/54c0068b0c988838.
Report an issue: GitHub.