hibernate many-to-many
hibernate many-to-many
https://www.baeldung.com/hibernate-many-to-many
https://www.baeldung.com/jpa-many-to-many
knowledge
many-to-many relationship, both sides can relate to multiple instances of the other side.

employee can be assigned to multiple projects and a project may have multiple employees working for it
- An employee table with employee_id as its primary key
- A project table with project_id as its primary key.
- A join table employee_project is required here to connect both sides.
In order to map a many-to-many association, we use the @ManyToMany, @JoinTable and @JoinColumn annotations.
The owning side is Employee so the join table is specified on the owning side by using the @JoinTable annotation in Employee class. The @JoinTable is used to define the join/link table. In this case, it is Employee_Project.
The @JoinColumn annotation is used to specify the join/linking column with the main table. Here, the join column is employee_id and project_id is the inverse join column since Project is on the inverse side of the relationship.
In the Project class, the mappedBy attribute is used in the @ManyToMany annotation to indicate that the employees collection is mapped by the projects collection of the owner side.
Practice
CREATE TABLE `employee` ( |