Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

orm - Hibernate hbm2ddl.auto, possible values, and what they do

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...