Two configuration items for hibernate configuration files
Hbm2ddl.auto: This property helps programmers to implement forward engineering, that is, to generate database scripts from Java code, resulting in a concrete table structure. 。
Value Create | Update | Create-drop | Validate create: The data table will be generated according to the. hbm.xml file, but each run will delete the last table, regenerate the table, even if two times without any change Create-drop: The table is generated according to the. hbm.xml file, but sessionfact The table is automatically deleted when the Ory is closed
Update: The most commonly used attribute values also generate tables based on the. hbm.xml file, but if the. hbm.xml file and the table structure of the corresponding data table in the database are different,
Hiberante will update the data table structure, but will not delete existing rows and columns
Validate: Compares the tables in the database and throws an exception if the columns in the. hbm.xml file do not exist in the data table
Format_sql: Whether to convert SQL to well-formed SQL. Value TRUE | False
Two. Hibernate one-to-one
<!--use Many-to-one to map 1-1 relationships--
<many-to-one name= "Mgr" class= "Com.atguigu.hibernate.one2one.foreign.Manager"
Column= "mgr_id" unique= "true" ></many-to-one>
<!--mapping 1-1: There is already a foreign key in the corresponding data table, and the current persistence class is mapped with one-to-one-
<!--
One end of a foreign key is required to use the one-to-one element, which uses the Property-ref property to specify that fields other than the primary key of the associated entity be used as the associated field
-
<one-to-one name= "Dept"
Class= "Com.atguigu.hibernate.one2one.foreign.Department"
property-ref= "Mgr" ></one-to-one>
Three. Hibernate many-to-many
<!--table: Specify an intermediate table--
<set name= "Items" table= "Categories_items" >
<key>
<column name= "c_id"/>
</key>
<!--use Many-to-many to specify many-to-many association relationships. Column executes the name of the foreign key column in the middle table of the persisted class in the set collection--
<many-to-many class= "Item" column= "i_id" ></many-to-many>
</set>
<set name= "Categories" table= "Categories_items" inverse= "true" >
<key column= "i_id" ></key>
<many-to-many class= "Com.atguigu.hibernate.n2n.Category" column= "c_id" ></many-to-many>
</set>
Hibernate learning Notes (ii)