The best way to map the JPA and Hibernate ManyToMany relationship

preview_player
Показать описание
In this video episode, I’m going to show you the best way to map a ManyToMany association when using JPA and Hibernate.

As simple as JPA annotations might be, it’s not always obvious how efficient they are behind the scenes.
Рекомендации по теме
Комментарии
Автор

Great video, Vlad.
Thank you very much.

Devivl
Автор

In my opinion, it's much simpler to just keep all three tables as the ones without any *ToMany relations and do all the stuff by hand. Looking at the complexity of the utility methods, as well as mapping verbosity of the entities, it will be easier to do all the activities in the code directly (better to read, better to modify and support). For example, if we need to add a new many-to-many relation, we just persist manually all two parents and then add a new entity representing many-to-many relation. The same is about removal - just remove the desired record(s) from the join table, and then delete the parent ones!

Exterminator
Автор

Thats great to know! but i dont understand why they would differ in the implementation between the list and the set, since to me at least it seems that they act simply as a container

dejvisbeqiraj
Автор

Could you please elaborate on the cases where it is better to map the Join Table in a separate JPA Entity?
Thanks in advance

MarkoGila-fo
Автор

What do you recommend, if there are multiple many to many relationship in the same join table?

Abhishekchandel