The last posting hibernate from the beginning to the Master (d) Basic mapping we've explained basic mappings and related concepts, and then we'll talk about a slightly more complex mapping--relational mapping.
Relational Mapping classification
Relationship mapping is the mapping of relationships between multiple related objects and multiple related tables on the basis of a basic mapping. The relationship mapping can be divided into seven types from the perspective of the corresponding relationship: one-to-one one-way association one-to-one bidirectional correlation One-to-many One-way Association multi-directional Correlation one-to-many Bidirectional Association Multi-pair multiple one-way association
Multiple to multiple bidirectional association
Next blog, we will explain each of these seven relationship mapping. Today we're going to talk about one one-to-one one-way association.
One-to-one One-way Association
A one-to-one one-way association is parsed from the perspective of an object, that is, there is a reference to another object (Idcard) in one object (person), and a reference to that object (person) is not present in another object (Idcard), so that the object (person) can be found when it is loaded To another object (Idcard). The class structure diagram looks like this:
The specific code looks like this:
public class Person {private int id;
private String name;
Private Idcard Idcard;
public int getId () {return id;
The public void setId (int id) {this.id = ID;
Public String GetName () {return name;
public void SetName (String name) {this.name = name;
Public Idcard Getidcard () {return idcard;
public void Setidcard (Idcard idcard) {this.idcard = Idcard;
} public class Idcard {private int id;
Private String Cardno;
public int getId () {return id;
The public void setId (int id) {this.id = ID;
Public String Getcardno () {return cardno;
} public void Setcardno (String cardno) {this.cardno = Cardno; }
}
Depending on the associated policy, the corresponding class structure generates a different table structure, which can be divided into primary key associations and unique foreign key associations.