• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Many-To-Many Association - 4 Ways

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In section 6.3.2 of "Hibernate In Action"


It's mentioned
In particular, a many-to-many association may always be represented as two many-to-one associations to an intervening class.

BUT the actual code (with not much explaination) is given as :



Now here there is only one <many-to-one> mapping instead of 2 ?
Moreover in the downloadable code, there are 4 ways given which are missing in the book...

WAY 1: This uses collections on both sides and uses <many-to-many> element. There are no additional columns in the underlying many-to-many join table..
[ I understood this scenario completely]

WAY 2: [ I didn't understood this case completely ]
They are using 2 one-to-many associations.
They introduced an intermediate class called CategorizedItem.
From the code it seems that they have
1 * * 1
Category -------> CategorizedItem -------->Item

That's why CategorizedItem contains (Item item)and (Category category) as it's properties...

Q-1 How these 1->*, *-> 1 associations is equivalent to * -> * association ?

Q-2 In the book, they have define CategorizedItem as component with parent as category. If CategorizedItem is component, then why <component> ismissing and moreover why CategorizedItem properties don't go in Category table?

A Lot Of Confusion !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic