Hibernate mapping parsing--correlation mapping (iv)

Source: Internet
Author: User

Here's a second way to implement a one-to-one correlation mapping, the unique Foreign Key association.


Unique FOREIGN Key Association: A Foreign Key association, which is intended to be used for many-to-one configurations, but can also be used to represent an affinity relationship if a unique limit is added.


A unique foreign Key association is also used in two ways, one-way and two-way. The object model is consistent with the single-direction associated with the primary key, and the resulting relationship pattern is different.


One-way unique foreign key:

Adopt <many-to-one> label to map, specify a multiple end Unique to be true, This limits the multiplicity of the multiple at one end.


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 "> 
  


Bidirectional unique FOREIGN Key:


The bidirectional unique foreign Key Association takes the <one-to-one> tag mapping and must be developed in the <one-to-one> Tag Property-ref Property is the name of the relationship field


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 "> 
   


!! Note: The relationship model of the two-way unique foreign key is consistent with the one-way model, or is maintained by the person, except that the object model becomes a two-headed arrow that holds references to each other.


Hibernate mapping parsing--correlation mapping (iv)

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.