Hibernate supports auto-build the table, it is convenient in the development stage, we can ensure automatic synchronization hbm the database table structure.
achieve:
Hbm2ddl.auto provided in the configuration file to configure the hibernate update, such as: the Xml Code <property name = "hbm2ddl.auto"> update </ property>;
update: The updated automatically indicates the entity class object table structure, automatically checks the database Hibernate startup, if the table is missing, automatically build the table; if the table columns are missing, automatically add columns.
There are other parameters:
create: When you start hibernate, automatically delete the original table, all of the new table, so every time after starting the previous data will be lost.
create-drop: When you start hibernate, automatically create a table, when the program is closed, the corresponding tables are automatically deleted. So at the end of the program, tables and data will no longer exist.
validate: Each time hibernate loaded, verified create a database table structure, and the only table in the database are compared, it does not create a new table, but will insert a new value.
Note that: the database is set up in advance, because hibernate will build the table, not building a database!