You can add this statement to hibernate. cfg. XML to automatically generate a data table.
<Property name = "hibernate. hbm2ddl. Auto"> Update </property>
Update: automatically updates the table structure based on the model object. When Hibernate is started, the database is automatically checked. If a table is missing, the table is automatically created. If a column is missing in the table, the column is automatically added.
There are other parameters:
Create: When Hibernate is started, the original table is automatically deleted and all new tables are created. Therefore, the previous data is lost after each start.
Create-drop: When Hibernate is started, tables are automatically created. When the program is closed, all corresponding tables are automatically deleted. So at the end of the program, the table and data will no longer exist.
PS: the database needs to be created in advance, because hibernate only creates tables and does not create databases.
========================================================== =
The table structure and data are constantly modified without reason during program execution. After a long time, I checked the hibernate database ing files and interface programs and found no errors, it was discovered at the end!
<Property name = "hibernate. hbm2ddl. Auto" value = "Update"/>
Explanation:
Hibernate. hbm2ddl. auto automatically validate or export 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. eg. validate
| Update | create-drop
In fact, this parameter is mainly used to: automatically create | update | verify the database table structure.
If you do not have this requirement, we recommend that you set value = "NONE ".
Meanings of other parameters:
Verify the structure of the created database table when loading hibernate in validate.
Create loads hibernate each time and re-creates the database table structure
Create-drop is created when Hibernate is loaded. Exit is to delete the table structure
Update load hibernate automatically updates the database structure
If the database table is lost or newly added, check the configuration of hibernate. hbm2ddl. Auto to set <Property
Name = "hibernate. hbm2ddl. Auto" value = "NONE"
/>
You can add this statement to hibernate. cfg. XML to automatically generate a data table.
<Property name = "hibernate. hbm2ddl. Auto"> Update </property>
Update: automatically updates the table structure based on the model object. When Hibernate is started, the database is automatically checked. If a table is missing, the table is automatically created. If a column is missing in the table, the column is automatically added.
There are other parameters:
Create: When Hibernate is started, the original table is automatically deleted and all new tables are created. Therefore, the previous data is lost after each start.
Create-drop: When Hibernate is started, tables are automatically created. When the program is closed, all corresponding tables are automatically deleted. So at the end of the program, the table and data will no longer exist.
PS: the database needs to be created in advance, because hibernate only creates tables and does not create databases.
========================================================== =
The table structure and data are constantly modified without reason during program execution. After a long time, I checked the hibernate database ing files and interface programs and found no errors, it was discovered at the end!
<Property name = "hibernate. hbm2ddl. Auto" value = "Update"/>
Explanation:
Hibernate. hbm2ddl. auto automatically validate or export 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. eg. validate
| Update | create-drop
In fact, this parameter is mainly used to: automatically create | update | verify the database table structure.
If you do not have this requirement, we recommend that you set value = "NONE ".
Meanings of other parameters:
Verify the structure of the created database table when loading hibernate in validate.
Create loads hibernate each time and re-creates the database table structure
Create-drop is created when Hibernate is loaded. Exit is to delete the table structure
Update load hibernate automatically updates the database structure
If the database table is lost or newly added, check the configuration of hibernate. hbm2ddl. Auto to set <Property
Name = "hibernate. hbm2ddl. Auto" value = "NONE"
/>