ART#205 - What mapping should you choose for extending ATG repository ?

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.

One-to-one Mapping

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.

One-to-many 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

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

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

Now that we know which mapping to choose for our requirements, we can accordingly move to design pattern for database and repository for each of these types. 




  1. Hi Yousuf,

    Please correct Many-to-Many instead of many-to-one in the above explanation under Many-to-Many Mapping.


    1. Thanks for pointing out the typo. It is corrected now.

  2. please give e-commerce examples for the above relationships

    1. All examples are present in further articles.



Get All The Latest Updates Delivered Straight Into Your Inbox For Free!