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)!