Ronny Shibley
Ronny Shibley

Reputation: 2155

Hibernate MySQL Find Unmapped Tables and Columns

I use Autogenerate DDL feature from Hibernate to create my tables and columns.

However, I end up deleting many columns in my entities but those columns remain in the database.

Is there a script that could identify those unmapped columns and tables so I could manually delete them?

Right now, I do it manually but it's becoming problematic as the database grows.

Upvotes: 1

Views: 294

Answers (2)

KayV
KayV

Reputation: 13835

The recommended thing is:

  1. We should use the hibernate.hbm2ddl.auto property only in the development environment, not is the production

  2. If hibernate.hbm2ddl.auto=create-drop, hibernate will drop and create a new database every time of deployment, that means we can track the database state and its consistency.

  3. If hibernate.hbm2ddl.auto=update, hibernate will only update the database with the changes to made in model/entity classes, but it should not be trusted for the production environment/database.

  4. hibernate.hbm2ddl.auto should be set to default for the production environment, so that no databases changes should be reflected from hibernate in production.

Upvotes: 1

Safeer Ansari
Safeer Ansari

Reputation: 790

I am afraid you there is no automated way to do that.

Alternatively you can drop the whole table before building and loading the project and let hibernate re-create it with your defined column names.

Upvotes: 1

Related Questions