In Hibernate tutorial, chapter 25 best practices says we should use 2 one-to-many relationship instead of one many-to-many with an intermediate link class. I can't see what is the benefit of it : why is it better to create a 3d entity while the many-to-many can generate a join table that is acting as this intermediate link. However this recommendation must be there for a good reason.
Can somebody explain the ground for this recommendation ? Thank you.
Many-to-many relationships quite often develop barnacles — extra data that is associated with the relationship itself, rather than either of the participants in the relationship (in my experience, this is the norm rather than the exception). For instance members and groups might be associated in a many-to-many way, and you want to know when a member joined a group, what their membership status is (new, pending, suspended, ...) and so on.
If you start by modelling the relationship directly as a many-to-many and write all your code accordingly, the very first extra column that hits the join table will break your model and a bunch of code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With