|
Answer» There can be 4 types of association mapping in hibernate. - One to One: A one-to-one association is similar to many-to-one association with a DIFFERENCE that the column will be set as unique. For example, an ADDRESS object can be associated with a single employee object. <one-to-one> element is used to define one-to-one association. The name attribute is set to the defined variable in the PARENT class. The column attribute is used to set the column name in the parent table which is set to unique so that only one object can be associated with another object.
- One to Many: In One-to-Many mapping association, an object can be associated with multiple OBJECTS. For example, Employee object relates to many Certificate objects. A One-to-Many mapping can be implemented using a Set java collection that does not contain any duplicate element. <one-to-many> element of set element indicates that one object relates to many other objects.
- Many to One: A many-to-one association is the most common KIND of association where an Object can be associated with multiple objects. For example, a same address object can be associated with multiple employee objects. <many-to-one> element is used to define many-to-one association. The name attribute is set to the defined variable in the parent class. The column attribute is used to set the column name in the parent table.
- Many to Many: A Many-to-Many mapping can be implemented using a Set java collection that does not contain any duplicate element. <many-to-many> element indicates that one object relates to many other objects and column attributes are used to link intermediate column.
|