53

I am looking at the Hibernate hbm2ddl.auto configuration property and its possible values:

  • validate
  • update
  • create
  • create-drop

What do all these values do?

The Hibernate Reference Documentation only talks briefly about create-drop, but doesn't say anything about the other values:

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

I found very useful explanations in these Stack Overflow questions:

But still nothing in the official documentation.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Danilo Piazzalunga
  • 7,590
  • 5
  • 49
  • 75
  • 1
    Check out the answers to this question: http://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do – Jason S Oct 18 '13 at 23:13
  • Actually, I linked to this very question. I was looking for *the* official explanation in Hibernate documentation. – Danilo Piazzalunga Nov 05 '13 at 13:44

3 Answers3

76

For hbm2ddl.auto property the list of possible options is:

  • validate: validate that the schema matches, make no changes to the schema of the database, you probably want this for production.
  • update: update the schema to reflect the entities being persisted
  • create: creates the schema necessary for your entities, destroying any previous data.
  • create-drop: create the schema as in create above, but also drop the schema at the end of the session. This is great in early development or for testing.
Sled
  • 18,541
  • 27
  • 119
  • 168
Ferdous Wahid
  • 3,227
  • 5
  • 27
  • 28
  • I tried to flush out your answers, please review my changes to make sure they reflect your original intent and are accurate. – Sled Nov 01 '14 at 01:13
  • 6
    note that **update** will not create a table that does not exists, while **create** will always truncate any existing data. there is no way to have an automatic way to tell hibernate to **create table only if it does not yet exist** – humanityANDpeace Jun 05 '17 at 11:12
  • 2
    @humanityANDpeace I always use update and I never faced "missing table" or something – hugo blanc Jun 08 '20 at 11:32
12

The link you provided is already the official documentation. So, there's nothing more official and comprehensive as-of today.

So I guess the answer to your question is two-fold:

I know this isn't the perfect answer you dreamt about, but this is actually all you have today.

But the good news is that the project is open-source, so you have all you need to help improve it :-).

Baptiste Mathus
  • 888
  • 2
  • 11
  • 18
4

The documentation has been updated to include this information. Here is a link to the official, current documentation for this feature.

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:

none
    No action will be performed.

create-only
    Database creation will be generated.

drop
    Database dropping will be generated.

create
    Database dropping will be generated followed by database creation.

create-drop
    Drop the schema and recreate it on SessionFactory startup. Additionally, drop the schema on SessionFactory shutdown.

validate
    Validate the database schema

update
    Update the database schema
Dario Seidl
  • 4,140
  • 1
  • 39
  • 55
Joel Harris
  • 1,966
  • 3
  • 20
  • 32