Hibernate hbm2ddl.auto does not delete columns using mysql

He adds new ones, but as far as I see, he does not abandon the old ones?

When I say old, I mean the properties of entity objects that are now completely removed, where they were previously present and annotated with @column

Are my only options for manually resetting the col command or changing the configuration value to create ? None of them are particularly charming.

Or something else?

+4
source share
2 answers

For what it's worth, NEVER ever use hbm2ddl.auto in any live / production database.

Yes, it "works as intended" that the "update" does not leave any columns that are not referenced (it is possible that you can use the "obsolete" databases that have columns that are not used by your hibernate application, but can be used external applications). However, under certain circumstances, hibernation can drop and recreate columns if, for example, you change the data type in your object. This is one of the reasons why you should never use it for any production system.

Personally, I would never trust the automated black box structure to handle changes to the datamodel in all but strictly local / dev environments. I always set it up so that in local development environments you can create drop-drops. After you start promoting your application to the central test / step, and then run it, all database changes are made by the database administrator: with good old-fashioned DDL scripts. Data is too valuable for the risk of a potential error or unexpected hibernation (or any other ORM / automated system). I even make sure that the database user configured in my applications does not even have the right to create / delete / modify the database, just to prevent disasters due to poor configuration in sleep mode.

So, to answer your question: if you want hibernate to always support your database reflecting your entities, then create-drop is your only option. Just never use it on anything other than local developer databases.

+11
source

I would look into liquibase to keep your database in sync with your enitities. Maybe a little bust, but worth it.

+1
source

All Articles