Types of Mapping in Hibernate or Relationship Multiplicity by R4R Team

In the Hibernate we have the following type of the mapping which are given below:

1. One To One Mapping 
2. One To Many Mapping 
3. Many To One Mapping 
4. Many To Many Mapping

1. One-to-One
A single AccountOwner has a single HomeAddress
A single HomeAddress has a single AccountOwner

2. One-to-Many
A single Account has many Transactions
Reverse of a many-to-one relationship

3. Many-to-One
Multiple Transactions belong to a single account
Reverse of a one-to-many relationship

4. Many-to-Many
Multiple Accounts have multiple AccountOwners
Often realized through two one-to-many relationships
A single Account has multiple AccountOwners
A single AccountOwner has multiple Accounts

Relationship Directionality

1. Unidirectional
a. Can only traverse objects from one side of the relationship
b. Example: Account : Transaction
c. Given an Account object, can obtain related Transaction objects.
d. Given a Transaction object, cannot obtain related Account object.

2. Bidirectional
a. Can traverse objects from both sides of the relationship
b. Example: Account : Transaction
c. Given an Account object, can obtain related Transaction objects.
Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!