This behaviour is expected using ddl-auto=update
and luckly it’s configurable.
Hibernate contains following key: hibernate.schema_update.unique_constraint_strategy
where:
- DROP_RECREATE_QUIETLY: Default option. Attempt to drop, then (re-)create each unique constraint. Ignore any exceptions being thrown.
- RECREATE_QUIETLY: Attempts to (re-)create unique constraints, ignoring exceptions thrown if the constraint already existed
- SKIP: Does not attempt to create unique constraints on a schema update.
In your case, I would recommend to use RECREATE_QUIETLY.
Documentation:
[1] https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl
[2] https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/tool/hbm2ddl/UniqueConstraintSchemaUpdateStrategy.html