Hibernate hbm2ddl auto possible values and their uses

+1 vote

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:

  • New tables
  • new columns in old tables
  • columns deleted
  • data type of a column changed
  • a type of a column changed it attributes
  • tables have been dropped
  • values of a column has changed

In each case what is the best solution?

Jun 18, 2018 in Java by developer_1
• 3,320 points
75,480 views

12 answers to this question.

+1 vote

The 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 when the SessionFactory is closed explicitly, typically when the application is stopped.
answered Jun 18, 2018 by Rishabh
• 3,620 points
+1 vote

hibernate.hbm2ddl.auto automatically validates and exports DDL to the schema when the sessionFactory is created.

  • create - doing creating a schema

    <entry key="hibernate.hbm2ddl.auto" value="create">
  • update - updating existing schema

    <entry key="hibernate.hbm2ddl.auto" value="update">
  • validate - validate existing schema

    <entry key="hibernate.hbm2ddl.auto" value="validate">
  • create-drop - create and drop the schema automatically when a session is starts and ends

    <entry key="hibernate.hbm2ddl.auto" value="create-drop">
answered Dec 7, 2018 by Nabarupa
+1 vote

hibernate.hbm2ddl.auto (e.g. none (default value), create-only, drop, create, create-drop, validate, and update)

Setting to perform SchemaManagementTool actions automatically as part of the SessionFactory lifecycle. Valid options are defined by the externalHbm2ddlName value of the Action enum:

drop

Database dropping will be generated.

create

Database dropping will be generated followed by database creation.

validate

Validate the database schema

update

Update the database schema

Source : Hibernate Documentation

answered Dec 7, 2018 by Shuvodip
This is wrong. only 4 values are there create,validate,update,create-drop. and by default it is validate.
0 votes

HBM2DDL_AUTO

static final String HBM2DDL_AUTO

Auto export/update schema using hbm2ddl tool. Valid values are update, create, create-drop and validate.

answered Dec 7, 2018 by Sukesh
0 votes

hbm2ddl.auto tells the hibernate whether Table in database need to be created or not

This property has four values mention below:

1)create : - if the value is create than hibernate always create new table .. if table is present in database than it delete it and recreate it… with that previous data in table is lost…

2)update :- if value is update than hibernate first validate that table is present in database or not , if present used that table or if not create a new table.

3) validate :- if value is validate than hibernate only verified that table is present or not..if table is not exit than throws exception.

4)create-drop: if value is create-drop than hibernate create a new table perform operation and delete that table immediately this value is used for testing of the hibernate code.

answered Dec 7, 2018 by Shuvodip Ghosh
0 votes
validate | update | create | create-drop these are the four properties that you can use from hibernate hbm2.dll.auto

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.
answered Dec 7, 2018 by Sukesh
0 votes
  • validate: validates that the existing database schema matches your mapping documents. update: updates an existing schema with incremental changes.
  • create:
  • create-drop: same as create, plus the database schema will be dropped when the SessionFactory is closed explicitly.
These are the four functionality of hbm2dll.auto
answered Dec 7, 2018 by Uttam
0 votes

The four possible values are as follows:

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.

answered Dec 7, 2018 by Meraj
0 votes

The possible values are 

  • Validate
  • update
  • create
  • create-drop
answered Dec 7, 2018 by Chester
0 votes

Four values are as follows:-

  • 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 when the SessionFactory is closed explicitly, typically when the application is stopped.

answered Dec 7, 2018 by Rana