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)