I see a lot of people confused when it comes to choosing mapping for their repository. This is a very important exercise in your database design, because if it is not done correctly, you may not be able to set-up your repository XML correctly, and if this is not done, you'll never be able to figure out what went wrong, and why your repository is functioning properly. Let us pick up various mapping topics and learn when to use them.
This one is pretty easy one.
Consider an example, wherein there is an "Employee". Now, an employee can only be associated with exactly one "homeAddress" at a time. Now, our "employee" can be one item-descriptor and "homeAddress" can be another. Conversely, a "homeAddress" can only have one employee (although, there might be two employees from a same home working in the same organization, but the chances are very very slim).
This is basically referred to as one-to-one mapping.
Consider a similar example, where an "Employee" has many "corporate credit cards". But a particular corporate credit card can be associated with exactly one "Employee". See below diagram for more details.
Many-to-one mapping is similar to above example, but is exactly the opposite. Here, consider an "Employee" can be associated with exactly one "Organization", but an "Organization" can have many employees.
See below diagram for more clarity:-
Many-to-many mapping is simply the concept of many entities being associated with many entities. For example, An "Employee" can be a part of multiple "meetings" during the day, and a "meeting" can have multiple "Employees" associated with it. See below diagram for details:-