Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate hbm2ddl.auto default value [duplicate]

What is the default value of

hibernate.hbm2ddl.auto

in hibernate cfg file mapping

is it possible to remove

<property name="hibernate.hbm2ddl.auto">update</property>

this mapping from config file

if i remove this property whether it affect my DB

???

like image 264
Anand K Nair Avatar asked May 17 '12 09:05

Anand K Nair


People also ask

What is the default value for Hibernate hbm2ddl Auto?

hbm2ddl. auto defaults to Hibernate not doing anything. Show activity on this post. Automatically validates or exports schema DDL to the database when the SessionFactory is created.

What does Hibernate hbm2ddl auto do?

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.

When we set create-drop value for hbm2ddl auto property when Hibernate will drop the table?

auto Create : If the value is CREATE then the hibernate first drops the existing tables data and structure, then creates new tables and executes the operations on the newly created tables. The only problem with the value “create” is, we lose existing table data.

Which of the following values can be used for Spring JPA Hibernate DDL-Auto Property?

You can set spring. jpa. hibernate. ddl-auto explicitly and the standard Hibernate property values are none , validate , update , create-drop .


3 Answers

That is really the answer: no validation, no update, no creation and no dropping takes place when omitting the setting from your configuration. The hibernate source code is the best documentation on Hibernate:

// from org.hibernate.cfg.SettingsFactory line 332 (hibernate-core-3.6.7)      
String autoSchemaExport = properties.getProperty(Environment.HBM2DDL_AUTO);
if ( "validate".equals(autoSchemaExport) ) settings.setAutoValidateSchema(true);
if ( "update".equals(autoSchemaExport) ) settings.setAutoUpdateSchema(true);
if ( "create".equals(autoSchemaExport) ) settings.setAutoCreateSchema(true);
if ( "create-drop".equals(autoSchemaExport) ) {
  settings.setAutoCreateSchema(true);
  settings.setAutoDropSchema(true);
}
like image 195
raphaëλ Avatar answered Oct 07 '22 16:10

raphaëλ


Just omitting hibernate.hbm2ddl.auto defaults to Hibernate not doing anything.

Already asked in SO . link

like image 28
Abhilash Avatar answered Oct 07 '22 18:10

Abhilash


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.

validate | update | create | create-drop
  • validate- existing schema
  • update- only update your schema once created
  • create- create schema every time
like image 16
Subhrajyoti Majumder Avatar answered Oct 07 '22 18:10

Subhrajyoti Majumder