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. Howeve开发者_开发技巧r 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.
精彩评论