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)