tags:

views:

72

answers:

1

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.

+5  A: 
Marcelo Cantos
+1 (and i think there are also performance reason for not using a many-to-many table: hibernate will have difficulties being optimal when updating the join table.)
Thierry
@Thierry, you can't avoid the "many-to-many" table (I prefer to call it the join table) when modelling a many-to-many relationship. What I'm saying is not that you shouldn't have a join table, but that you should model the join table directly in the ORM, rather than implying it via collection properties on the related objects.
Marcelo Cantos
Yes, i completely agree with you, and there is a typo in what i wrote : i wanted to say that many-to-many may be less efficient than two many-to-one (so instead of 'for not using' i wanted to write 'for using', which is quite the opposite meaning -_-). So even when you know you won't have any other property in the join table, it might be a good idea to consider mapping it as an entity.
Thierry