Monday, September 18, 2017

What is hibernate.hbm2ddl.auto

More about hibernate.hbm2ddl.auto

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

By default, it does not perform any creation or modification automatically on DB. If the user sets one of the below values then it is doing DDL schema changes automatically.
·         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">

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:<table name>
·         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.



No comments:

Post a Comment