Hibernate from entry to Mastery (eight) One-to-many one-way correlation mapping

Source: Internet
Author: User

The last blog post hibernate from Getting started to mastering (vii) multi-pair one-way association mapping we have mainly explained the multiple to one one-way association mapping, this time we continue to explain a pair of multiple one-way mapping.

One-to-many One-way Association mapping

Before explaining a One-to-many one-way association, follow our usual practice by looking at its corresponding class structure diagram and code. Specifically as follows:

 public class Classes {private int id;          
    private String name;  
    Private Set students;  
    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 Set getstudents () {return students;  
    The public void setstudents (Set students) {this.students = students;       
    } public class Student {private int id;  
    private String name;  
    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; }  
}

Comparing a One-to-many association mapping with a many-to-many correlation mapping we've talked about earlier, we can see that the two mapping principles are consistent, with a foreign key added to one end of the multiple. The difference is that the relationship between the maintenance is different, more on one maintenance is more point to one of the relationship, with this relationship, in the loading time can be a load up, a one-to-many maintenance is a point of many relations, with this relationship, in the loading of a time can be more load up.

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.