What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do

前端 未结 13 2498
轮回少年
轮回少年 2020-11-21 04:47

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 w

13条回答
  •  Happy的楠姐
    2020-11-21 05:37

    Although it is quite an old post but as i did some research on the topic so thought of sharing it.

    hibernate.hbm2ddl.auto

    As per the documentation it can have four valid values:

    create | update | validate | create-drop

    Following is the explanation of the behaviour shown by these value:

    • create :- create the schema, the data previously present (if there) in the schema is lost
    • update:- update the schema with the given values.
    • validate:- validate the schema. It makes no change in the DB.
    • create-drop:- create the schema with destroying the data previously present(if there). It also drop the database schema when the SessionFactory is closed.

    Following are the important points worth noting:

    • In case of update, if schema is not present in the DB then the schema is created.
    • In case of validate, if schema does not exists in DB, it is not created. Instead, it will throw an error:- Table not found:
    • In case of create-drop, schema is not dropped on closing the session. It drops only on closing the SessionFactory.
    • In case if i give any value to this property(say abc, instead of above four values discussed above) or it is just left blank. It shows following behaviour:

      -If schema is not present in the DB:- It creates the schema

      -If schema is present in the DB:- update the schema.

    • 提交回复
      热议问题