|
Using dialect MySQL5InnoDBDialect, in the class org.hibernate.cfg.Configuration, in the method public List<SchemaUpdateScript> generateSchemaUpdateScriptList(Dialect dialect, DatabaseMetadata databaseMetadata)..., when the @Column(unique=true) is present, Hibernate uses the default flag: UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY, which generates a query: alter table "tname" drop "constraint" uk_.... It generates a syntax exception, since MySQL requires the syntax alter table "tname" drop "index" uk_... According to MySQL docs in http://dev.mysql.com/doc/refman/5.1/en/alter-table.html there is an "alter table tname add constraint unique index...", but there is NOT an "alter table tname drop constraint...", just an "alter table tname drop index..." (no "constraint" word for dropping, just drop "index"). Since the org.hibernate.dialect.unique.DefaultUniqueDelegate class (and its specializations) don't generate the command with the right syntax, the only option is to use the configuration hibernate.schema_update.unique_constraint_strategy=RECREATE_QUIETLY, which skips the drop command, but is clearly it not wanted, just a temporary workaround until the syntax creation is correct.
|