Hibernate learning Notes (ii)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.