From the course: Java Persistence with JPA and Hibernate
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
Many-to-many relationships - JPA Tutorial
From the course: Java Persistence with JPA and Hibernate
Many-to-many relationships
- [Instructor] Unlike one-to-one and one-to-many relationships, it's never possible to have many-to-many relationships at database level, but this kind of relationships can exist between entity classes. For example, a user can belong to many groups and a group can have many users. To implement a many-to-many relationship, there needs to be a join table in the database, but the join table doesn't map to any entity class in ORM. It's only used behind the scenes to create the relationship. In a many-to-many relationship, any one of the entities can be the owner. Also, the relationship can be unidirectional, or bidirectional. Let's first map a unidirectional many-to-many relationship. Start by running the mariadb 06_03 sql script. In the database, there's the user and group tables. Apart from them, there's a join table, user_group, with user ID and group ID in it. I've also created two entity classes, user and group, for you. Let's start with the unidirectional relationship from the group…
Contents
-
-
-
-
-
-
-
-
(Locked)
One-to-one relationships8m 13s
-
@OneToMany and @ManyToOne annotations in a relationship8m 8s
-
(Locked)
Many-to-many relationships7m 29s
-
(Locked)
Inheritance9m 40s
-
(Locked)
More inheritance strategies9m 25s
-
(Locked)
Composition relationship11m 6s
-
(Locked)
Challenge: Art Class Management app, part 41m 58s
-
(Locked)
Solution: Art Class Management app, part 44m 41s
-
(Locked)
-
-
-