1 <PropertyName= "Hbm2ddl. Auto">Create</Property>
Hibernate reference documentation 3.3.1 is explained as follows: 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 hibernate. hbm2ddl. Auto parameter is mainly used for: automatic creation, update, and verification of the database table structure. If this is not the requirement, set value = "NONE" is recommended ".
Create : The last generated table is deleted each time Hibernate is loaded, then, you can generate a new table based on your model class, even if there are no changes twice. This is an important cause of data loss in the database table.
Create-drop : A table is generated based on the model class each time Hibernate is loaded, but sessionfactory is disabled, the table is automatically deleted.
Update : The most common attribute, when Hibernate is loaded for the first time, the table structure will be automatically created based on the model class (the premise is that the database is created first). When Hibernate is loaded, the table structure will be automatically updated based on the model class, even if the table structure is changed, the row in the table still does not delete the previous row. Note that after the application is deployed to the server, the table structure will not be created immediately. It will not be created until the application runs for the first time.
validate : each time Hibernate is loaded, the database table structure is verified and compared with the table in the database, no new table is created, but a new value is inserted.
Let's talk about "nonsense": When we use hibernate. hbm2ddl. Auto = create, Hibernate uses hbm2ddl to generate database schema. When we comment out the hbm2ddl attribute in the hibernate. cfg. xml file, we cancel using hbm2ddl to generate database schema at startup. Usually you need to open it only when you perform unit tests repeatedly, but running hbm2ddl again will delete everything you saved (drop)-the meaning of the create configuration is: "Drop the tables from scema and recreate them when creating sessionfactory ". Note: many new hibernate beginners will fail in this step. From time to time, we will see questions about the table not found error message. However, as long as you follow the steps described above, this problem will not occur, because hbm2ddl will create a database schema at the first run, and subsequent applicationsProgramYou can continue to use this schema after the restart. If you modify the ing or database schema, you must re-open hbm2ddl.
Reprinted from: http://blog.sina.com.cn/s/blog_417c76730100gyap.html