On Hibernate relational Mapping (4)

Source: Internet
Author: User
Tags generator

Following the previous blog

Many-to-many association mappings (unidirectional)

Many-to-many-object relational mappings require adding a new table to complete the basic mapping.

    • Hibernate The intermediate table is automatically generated
    • Hibernate Use many -to-many tags to represent many-to-many associations, many-to-many associative mappings, in entity classes, as with a pair, are also represented by a set.

As shown


through User can view Role of Information

User the mapping file


Role the mapping file


Many-to-many association mappings (bidirectional)

Bidirectional many-to-many-object relationship mapping, both sides can load the other side, both directions need to add tag mapping.

Be aware that:

* Generate intermediate table names must be the same

* Generate intermediate table fields must be the same



User the mapping file:


Role the mapping file


Difference: one-way many-to-many and bidirectional many-to-many storage structures have no difference, but their mapping files are different and the loading process is distinct.

Relationship Mapping Summary

To sum up, it can be seen that the same class of mappings, either unidirectional or bidirectional, their storage structure is the same, the reason for the mapping file is different, because the loading time is different (when adding and deleting) that is to pass who can see who, or can see each other.

whether it's a one-to-many, many-to-many, or one-on relationship, for example:Student---"Idcard, students want to know the card information, thenStudentend there will beIdcardin turn is a two-way relationship, byIdcardwant to knowStudentthe information, thenIdcardend will have toStudentreferences (the embodiment of the entity relationship)!



Related Article

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.