Home > DeveloperSection > Forums > Hibernate hbm2ddl.auto possible values and what they do?
Jayne Spooner
Jayne Spooner

Total Post:21

Points:147
Posted on    July-14-2015 7:08 AM

 Java Java 
Ratings:


 1 Reply(s)
 734  View(s)
Rate this:
I really want to know more about the update, export and the values that could be given to hibernate.hbm2ddl.auto
I need to know when to use the update and when not? And what is the alternative?

These are changes that could happen over DB:

  1. New tables
  2. new columns in old tables
  3. columns deleted
  4. data type of a column changed
  5. a type of a column changed it attributes
  6. tables have been dropped
  7. values of a column has changed
  8. In each case what is the best solution?


Mayank Tripathi
Mayank Tripathi

Total Post:397

Points:3117
Posted on    July-14-2015 7:35 AM

hibernate.hbm2ddl.auto Automatically validates or exports schema DDL to the database when the SessionFactory is created. With create-drop, the database schema will be dropped when the SessionFactory is closed explicitly.

e.g. validate | update | create | create-drop

So the list of possible options are,

validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.

The configuration property is called hibernate.hbm2ddl.auto

In our development environment we set hibernate.hbm2ddl.auto=create-drop to drop and create a clean database each time we deploy, so that our database is in a known state.

In theory, you can set hibernate.hbm2ddl.auto=update to update your database with changes to your model, but I would not trust that on a production database. An earlier version of the documentation said that this was experimental, at least; I do not know the current status.

Therefore, for our production database, do not set hibernate.hbm2ddl.auto - the default is to make no database changes. Instead, we manually create an SQL DDL update script that applies changes from one version to the next. 

Don't want to miss updates? Please click the below button!

Follow MindStick