1

If I have understood right, in domain driven design there are repositories for only aggregate root objects. So what is the right way to implement, for example, paging (or access control filtering) for those objects which are child objects of roots.

Example:

@Entity
public class Person extends AbstractPersistable<Long> {

  @OneToMany
  private List<Competence> competences = new ArrayList<>();

  public void addCompetence( Competence competence ) {
     this.competences.add( competence );
  }

  public List<Competences> competences() {
     return this.competences;
  }

}

So if I first get person object from repository and then I'd like to send subset (page) of competences to my front end? It not make sense to create CompetenceRepository to find competences by person because it brokes the whole idea of aggregate roots... For now I have used Spring Data JPA.

Toni
  • 167
  • 5
  • You never query for aggregate root children, because: 1) conceptually, an AR never has children, 2) an aggregate represents **one whole concept** , it's all or nothing, you don't get to pick which implementation detail you want. – MikeSW Aug 21 '15 at 18:43

2 Answers2

3

A popular approach is to avoid using the domain model (which is a transactional model optimized for processing commands) for queries. You can read about that a little more by searching for CQRS.

plalx
  • 42,889
  • 6
  • 74
  • 90
0

This sounds like there are few processes that needs to be defined.

What application / part of application that requires a paging of competences?

Paging part of a domain model to me does not belong to be part of a domain / business rules. It is an application concern.

The application service layer from DDD would probably be the place to put this. You could create a service that helps your particular application to display the competences paging.

Leon
  • 41
  • 1
  • 5