I have two classes with many-to-many relation so I created a join table in-between them (a very classic example!)
In java+hibernate I want to know which way is better?
having a manytomany relation between these two class using hibernate manytomany annotation?
Or as the way I implemented in database having :
table1—>one-to-many—>join table—>many-to-one—>table2
then follow the same classic rule in hibernate?
Many-to-many is better if you do not have attributes for this relation. It describes relationship between your entities simpler way and without additional “join entity”. Entities do not have to mirror join tables, that just makes entity graph more complex in the case of pure join table.
If there is need to have additional attributes in relationship, then you have to go for intermediate entity approach.