Hbm2ddl.auto=update recreating existing indexes after drop

We are facing problem with the recreation of existing indexes when hbm2ddl.auto is set to ‘update’.
We have tables with millions of data and it is dropping the existing indexes and creating again (which is taking too long to start the server).

Blockquote For example: I can see the following statements while server startup:

Hibernate: alter table order drop index UK_nv4v3d33juoq0x0iwtub87ftw
Hibernate: alter table order add constraint UK_nv4v3d33juoq0x0iwtub87ftw unique (order_id)

We are using Hibernate 5.3.7.Final. In hibernate config file ‘MySQL5Dialect’ dialect being used.

I m not sure if this is an issue? I am referring the link: https://forum.hibernate.org/viewtopic.php?t=928084
Not sure if it is logged anywhere.

Please confirm and if anybody can explain why it is happening.

Hi, any news on this?

Another link: https://stackoverflow.com/questions/60138525/hibernate-mysql57dialect-why-is-it-trying-to-drop-indexes-on-update

Of course using hibernate.hbm2ddl.auto=update is not a good idea in production, but I’m creating (flyway-) update-scripts with the help of org.hibernate.tool.hbm2ddl.SchemaUpdate and see the same drop-index-create-index-stuff, although apparently only for unique indexes.

Maybe @vlad has an explanation for this?

Was definitely not the case in Hibernate 4.3.11 (we are in the process of upgrading)

@drahkrub Hi. I noticed the mention in your answer. I haven’t been working for Red Hat since March 2019, hence I don’t have the time to answer questions on this forum. You should ping one of the Hibernate ORM core developers. Cheers!

@vlad Many thanks for your message! And sorry to hear that - bad for Red Hat for sure and hopefully no problem for you. You’ve done a great work - keep it up!

ping @gbadner - do you know the reason for the re-creation of unique indexes?

1 Like

Hi. We are having exact same issue with recreating only one (of many) unique index every time we run spring boot app with hibernate.hbm2ddl.auto=update property set.
We are using Hibernate 5.3.10.Final with PostgreSQLDialect.