views:

1176

answers:

1

I'm a newbie in Database design and in Hibernate too. I started reading the documentation for Hibernate. It talked about "Collection Mapping", "Association Mapping" and "Component Mapping". I am not understanding the difference between them and not sure about when to use what in one-to-many/many-to-one/many-to-many relationships. To me, they all seem to do pretty much the same thing...

Could you explain the differnces between "Collection Mapping", "Association Mapping" and "Component Mapping" as refered by the Hibernate doc? Examples of when is the best to use which mapping would be appreciated.

PS. I don't know if this is too general of a question to ask here. If you think it is, sorry for wasting your time. Any suggestions to a good general text or website would be good too.

Thank you!!

+3  A: 
  • Collection mapping refers to a one-to-many or many-to-many relationship which will be mapped by using an implementation of java.util.Collection.

  • Association mapping refers to a many-to-one or one-to-one relationship which will be mapped by using another class which you have mapped in Hibernate (also called an "entity"). The associated object has its own lifecycle and is simply related to the first object.

  • Component mapping refers to mapping a class (or collection of classes) whose lifecycle is bound tightly to the parent. This is also called "composition" in the strict definition of the word in object-oriented programming. Basically if you delete the parent object the child object should also be deleted; it also cannot exist on its own without a parent.

cliff.meyers