Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between different mapping types in Hibernate?

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!!

like image 714
tomato Avatar asked Feb 14 '09 00:02

tomato


People also ask

What are different types of mapping in hibernate?

The main basic types of mapping are:Primitive Types. Date and Time Types. Binary and Large Object Types. JDK-related Types.

What is hibernate mapping Onetoone mapping?

Define Hibernate Mapping FileThe <many-to-one> element will be used to define the rule to establish a one-to-one relationship between EMPLOYEE and ADDRESS entities, but column attribute will be set to unique constraint and rest of the mapping file will remain as it was in case of many-to-one association.

What is Manytoone mapping?

The Many-To-One mapping represents a single-valued association where a collection of entities can be associated with the similar entity. Hence, in relational database any more than one row of an entity can refer to the similar rows of another entity.


1 Answers

  • 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.

like image 198
cliff.meyers Avatar answered Sep 28 '22 09:09

cliff.meyers