hibernate.hbm2ddl.auto=create on an empty database tries to drop foreign keys on tables that don't exist

Description

When creating a new SessionFactory with hibernate.hbm2ddl.auto=create on an empty database, Hibernate attempts to drop foreign keys on tables that do not exist yet.

The culprit appears to be SchemaManagementToolCoordinator calling SchemaDropper.doDrop() without checking if the schema actually exists first: https://github.com/hibernate/hibernate-orm/blob/0a2a709f9eb9954fd1a570c0779d0f510d8c045b/hibernate-core/src/main/java/org/hibernate/tool/schema/spi/SchemaManagementToolCoordinator.java#L137

This ends up trying to drop the foreign keys at https://github.com/hibernate/hibernate-orm/blob/17de173cb5334d866f1886d3e057f49a6c987bad/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/SchemaDropperImpl.java#L240 and results in an exception like

Environment

hibernate core 5.1.0.Final
MySQL

Assignee

Unassigned

Reporter

Adam Walsh

Fix versions

None

backPortable

None

Suitable for new contributors

Yes, likely

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure