One-way n-n: (Catogory-item) A category that corresponds to multiple entries, one entry for multiple categories
A. Take the reference to a collection with entries in the category class as an example:
B. Representation in the database: Create a new table with the foreign key associated with the primary key of the category and the entry to make the new table's federated primary key.
C. Mapping configuration: Configure a Foreign key mapping relationship in the category table
D Test:
Save
A four INSERT statement will be executed to insert the kind and entry and then execute four INSERT statements to insert the association relationship into the Category_item table;
Get:
Gets a collection of category association objects that are lazy loaded;
When getting the item collection data, an inner join is used, that is, the relationship table and the Entry table are connected,
Two. For bidirectional many-to-many, add on a one-way basis
A. The item class in the table adds a collection reference for the category:
C. Entry mapping Table add mapping Relationship:
Special Note : bidirectional Many-to-many, one side <set> elements need to set inverse=true, only a party to maintain the association, or a primary key conflict (because there will be duplicate insert record),
The above configuration has not been added, need to add on ;
Hibernate object Relationship Implementation (c) Many-to-many implementations