Hibernate from Getting Started to mastering (v.) One-to-one One-way association mapping

Source: Internet
Author: User
Tags reference

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.

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.