Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 131763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:09:24+00:00 2026-05-11T06:09:24+00:00

I am currently working on rewriting an application to use Data Mappers that completely

  • 0

I am currently working on rewriting an application to use Data Mappers that completely abstract the database from the Domain layer. However, I am now wondering which is the better approach to handling relationships between Domain objects:

  1. Call the necessary find() method from the related data mapper directly within the domain object
  2. Write the relationship logic into the native data mapper (which is what the examples tend to do in PoEAA) and then call the native data mapper function within the domain object.

Either it seems to me that in order to preserve the ‘Fat Model, Skinny Controller’ mantra, the domain objects have to be aware of the data mappers (whether it be their own or that they have access to the other mappers in the system). Additionally it seems that Option 2 unnecessarily complicates the data access layer as it creates table access logic across multiple data mappers instead of confining it to a single data mapper.

So, is it incorrect to make the domain objects aware of the related data mappers and to call data mapper functions directly from the domain objects?

Update: These are the only two solutions that I can envision to handle the issue of relations between domain objects. Any example showing a better method would be welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:09:24+00:00Added an answer on May 11, 2026 at 6:09 am

    I’m afraid you’ve slightly misunderstood the intention of the Repository pattern.

    The Repository is meant to behave like an in-memory collection of a particular domain object, usually an aggregate root:

    interface EmployeeRepository {     List<Employee> retrieveBy(Criteria someCriteria);     void store(Employee someEmployee);     int countOf(Criteria someCriteria);     // convenience methods     Employee retrieveById(String id);     Employee retrieveBySSN(String ssn); } 

    Clients of this code have no idea whether the collection is in memory, like you’d have for unit-testing, or talking to an ORM mapper in some cases, or calling a stored procedure in others, or maintaining a cache for certain domain objects.

    This still doesn’t answer your question. In fact, you could potentially have domain objects have save() and load() methods that delegate to the right repository. I don’t think this is the right way to go because persistence is almost never a part of the business domain, and it gives your domain object more than one reason to change.

    Check out this related question for more rambling.

    In response to some comments on this answer:

    A valid criticism. However, I’m still confused then on how to get a single domain object or a collection of related domain objects when within the context of an existing domain object. – gabriel1836

    Let’s say an Employee has many Skills. I see nothing wrong with the Employee Repository calling a Skill Repository like this:

    // assume EmployeeRepository talks to a DB via sprocs public Employee retrieveById(String id) {     ResultSet employeeResultSet = this.database.callSproc('PROC_GetEmployeeById',          new Object[] { id });      List<Skill> skills =          new SkillRepository().retrieveBy(new EqualsCriteria('EmployeeId', id));      Employee reconstructed = new EmployeeFactory().createNew().                                   fromResultSet(employeeResultSet).                                   withSkills(skills).                                   build();      return reconstructed;     } 

    Another route is instead of calling the Skill Repository, have the Employee Repository call the, in this example, stored procedure to load the result set for skills, then delegate to a Skill Factory to get the list of Skills.

    Can’t I make a call to the Repository and whether it issues a call to the data mapper or loads the object in-memory is its concern, isn’t it? – gabriel1836

    Exactly right. I usually mock out the entire data tier in my unit tests this way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I'm working with a big, old and extremely poorly written ASP.NET 1.1 application
Am working on a business layer for a complex web application and am temporary
I am currently working on a silverlight client, making use of a web server,
I'm currently working on a solution which needs to use both Silverlight 3.0 and
I am currently doing some work for a company that runs a legacy web
I've got a medium scale project (a turn-based game) that's currently written in C/C++.
I am working on a pet project and am at the research stage. Quick
I have designed a stylesheet/javascript files bundler and minifier that uses a simple cache
I've got a rather confusing problem. Web Service A - Called directly by Win32

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.