Hibernate hbm2ddl.auto, possible values, and what

2019-01-14 05:56发布

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.

3条回答
劳资没心,怎么记你
2楼-- · 2019-01-14 06:07

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 :-).

查看更多
贼婆χ
3楼-- · 2019-01-14 06:22

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.
查看更多
不美不萌又怎样
4楼-- · 2019-01-14 06:25

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

http://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl

查看更多
登录 后发表回答