Hibernate mapping parsing--correlation mapping (III)

Source: Internet
Author: User

The following is an introduction to hibernate, another way of associating mappings.


There are two implementation strategies for one-to-single affinity mappings: primary key affinity mappings and unique foreign Key association mappings.


PRIMARY KEY affinity mapping: Let two objects have the same primary key value to justify the one by one correspondence between them; The database table does not have additional fields to maintain the relationship between them, and is only associated with the primary key of the table.




1. One-to-one primary key association:


Object Model:



Relational Model:


IdCard.hbm.xml

<?xml version= "1.0"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd ">

Person.hbm.xml

<?xml version= "1.0"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd ">

2. Bidirectional one-to-one correlation


Object Model:


Relational Model:



IdCard.hbm.xml

<?xml version= "1.0"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd ">


Person.hbm.xml

<?xml version= "1.0"? ><! DOCTYPE hibernate-mapping Public "-//hibernate/hibernate mapping DTD 3.0//en" "http://hibernate.sourceforge.net/ Hibernate-mapping-3.0.dtd ">


The difference between a one-way and a-way is that two-way Idcard joins the <one-to-one> tag, indicating that hibernate will load the associated object on the primary key,<one-to-one> does not affect the storage. only affects loading.


Next article: one-to-one the second mapping method is the unique foreign Key association.

Hibernate mapping parsing--correlation mapping (III)

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.